QOJ.ac

QOJ

Limite de temps : 6 s Limite de mémoire : 32 MB Points totaux : 100

#594. 数组

Statistiques

考虑一个大小为 $n \times m$ 的数组,其中填满了互不相同的整数。允许对数组进行以下操作:

  • 交换两行,
  • 交换两列。

如果一个数组可以通过上述操作序列变换为另一个数组,我们称这两个数组是相似的。

编写一个程序,对于给定的多组数组对,判断每一对数组是否相似。

输入格式

标准输入的第一行包含一个整数 $t$ ($1 \le t \le 10$),表示数组对的数量。随后是各组数组对的描述。

每组描述的第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 1\,000$),由空格分隔,分别表示数组的行数和列数。

接下来的 $n$ 行描述第一个数组。其中第 $i$ 行包含 $m$ 个整数 $a_{i,j}$ ($-1\,000\,000 \le a_{i,j} \le 1\,000\,000$),由空格分隔,表示第一个数组第 $i$ 行的元素。

接下来的 $n$ 行描述第二个数组。其中第 $i$ 行包含 $m$ 个整数 $b_{i,j}$ ($-1\,000\,000 \le b_{i,j} \le 1\,000\,000$),由空格分隔,表示第二个数组第 $i$ 行的元素。

所有出现在任一数组中的数字均互不相同。

输出格式

程序应向标准输出打印 $t$ 行。第 $k$ 行应包含一个单词:“TAK”(波兰语中的“是”),如果第 $k$ 对数组相似,否则输出“NIE”(波兰语中的“否”)。

样例

输入 1

2
4 3
1 2 3
4 5 6
7 8 9
10 11 12
11 10 12
8 7 9
5 4 6
2 1 3
2 2
1 2
3 4
5 6
7 8

输出 1

TAK
NIE

说明 1

第一对数组是相似的。要将第一个数组转换为第二个数组,只需交换前两列,然后交换第一行与最后一行,以及第二行与第三行即可。

第二对数组不相似。观察可知,它们单元格中的数值集合不同。

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.