QOJ.ac

QOJ

حد الوقت: 20 s حد الذاكرة: 1024 MB مجموع النقاط: 7

#12417. 迹

الإحصائيات

Vestigium 在拉丁语中意为“痕迹”。在本题中,我们将处理拉丁方阵和矩阵的迹。

方阵的迹是主对角线(从左上角到右下角)上数值之和。

如果一个 $N \times N$ 的方阵中每个单元格都包含 $N$ 个不同值中的一个,且没有任何值在行或列中重复出现,则称其为拉丁方阵。在本题中,我们仅处理“自然拉丁方阵”,即 $N$ 个值均为 $1$ 到 $N$ 之间的整数。

给定一个仅包含 $1$ 到 $N$ 之间整数的矩阵,我们希望计算它的迹,并检查它是否为自然拉丁方阵。为了提供一些额外信息,我们不直接判断矩阵是否为自然拉丁方阵,而是请你计算包含重复元素的行数和列数。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例的第一行包含一个整数 $N$,表示矩阵的大小。随后有 $N$ 行,第 $i$ 行包含 $N$ 个整数 $M_{i,1}, M_{i,2}, \dots, M_{i,N}$,其中 $M_{i,j}$ 是矩阵第 $i$ 行第 $j$ 列的整数。

输出格式

对于每个测试用例,输出一行 Case #x: k r c,其中 $x$ 是测试用例编号(从 $1$ 开始),$k$ 是矩阵的迹,$r$ 是矩阵中包含重复元素的行数,$c$ 是矩阵中包含重复元素的列数。

数据范围

$1 \le T \le 100$ $2 \le N \le 100$ $1 \le M_{i,j} \le N$,对于所有 $i, j$。

样例

输入格式 1

3
4
1 2 3 4
2 1 4 3
3 4 1 2
4 3 2 1
4
2 2 2 2
2 3 2 3
2 2 2 3
2 2 2 2
3
2 1 3
1 3 2
1 2 3

输出格式 1

Case #1: 4 0 0
Case #2: 9 4 4
Case #3: 8 0 2

说明

在样例 1 中,输入是一个自然拉丁方阵,这意味着没有任何行或列包含重复元素。主对角线上的四个值均为 $1$,因此迹(它们的和)为 $4$。

在样例 2 中,所有的行和列都包含重复元素。请注意,无论行或列中重复元素的数量或重复频率如何,每个包含重复元素的行或列仅被计数一次。此外,请注意 $1$ 到 $N$ 范围内的某些整数可能在输入中缺失。

在样例 3 中,最左侧和最右侧的列包含重复元素。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.