QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#15710. 密室 2

Statistiques

你正在玩游戏《Henry Spotter与密室2》(Henry Spotter and the Chamber of Secrets 2)。

你想解锁下一个关卡——密室。入口大门上有 $n$ 个面板,每个面板显示一个长度为 $m$ 的符号序列。乘积 $nm$ 是偶数。系统通过以下四个步骤,从一个秘密排列生成这些序列:

  • 首先,从一个秘密排列 $[p_1, p_2, \dots, p_{nm/2}]$ 开始;
  • 然后,通过将该秘密排列与自身拼接来重复它,形成数组 $[b_1, b_2, \dots, b_{nm}]$;
  • 接着,将该数组分割成 $n$ 个连续的块,即长度为 $m$ 的互不相交的子数组;
  • 最后,将这些块以任意顺序打乱并分配到各个面板上。

给你系统生成的最终 $n$ 个面板序列。第 $i$ 个面板显示 $[a_{i,1}, a_{i,2}, \dots, a_{i,m}]$。你的任务是还原一个可能的原始秘密排列 $[p_1, p_2, \dots, p_{nm/2}]$。对于给定的输入,保证至少存在一个解。如果存在多个合法的秘密排列,输出其中任意一个即可。

两个数组 $[x_1, x_2, \dots, x_{k_1}]$ 和 $[y_1, y_2, \dots, y_{k_2}]$ 的拼接是指长度为 $k_1 + k_2$ 的数组 $[x_1, x_2, \dots, x_{k_1}, y_1, y_2, \dots, y_{k_2}]$。

长度为 $l$ 的排列是一个由 $1$ 到 $l$ 的 $l$ 个不同整数以任意顺序组成的数组。例如,$[2, 3, 1, 5, 4]$ 是一个排列,但 $[1, 2, 2]$ 不是排列($2$ 在数组中出现了两次),$[1, 3, 4]$ 也不是排列($l = 3$ 但数组中出现了 $4$)。

输入格式

每个测试点包含多个测试用例。第一行包含测试用例的数量 $t$ ($1 \le t \le 100$)。接下来是测试用例的描述。

每个测试用例的第一行包含两个整数 $n, m$ ($1 \le n \le 70, 1 \le m \le 70$) —— 面板的数量以及每个显示序列的长度。

接下来的 $n$ 行中,第 $i$ 行包含 $m$ 个整数 $a_{i,1}, a_{i,2}, \dots, a_{i,m}$ ($1 \le a_{i,j} \le nm/2$),表示第 $i$ 个面板上显示的序列。

注意,所有测试用例中 $n$ 和 $m$ 的总和没有额外限制。

输出格式

对于每个测试用例,输出单行,包含一个秘密排列 $[p_1, p_2, \dots, p_{nm/2}]$,使得上述过程可以生成这 $n$ 个面板序列 $[a_{i,1}, a_{i,2}, \dots, a_{i,m}]$。对于给定的输入,保证至少存在一个解。

样例

输入样例 1

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

输出样例 1

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

说明

样例 1 说明:

在第一个测试用例中,一个合法的秘密排列是 $[p_1, p_2, \dots, p_{nm/2}] = [5, 6, 3, 4, 1, 2]$:

  • 数组 $[b_1, b_2, \dots, b_{nm}]$ 是两个 $[p_1, p_2, \dots, p_{nm/2}] = [5, 6, 3, 4, 1, 2]$ 的副本拼接而成的结果;
  • $[b_1, b_2, \dots, b_{nm}]$ 被分割为以下块:$[5, 6]$,$[3, 4]$,$[1, 2]$,$[5, 6]$,$[3, 4]$,$[1, 2]$;
  • 打乱后,最终的面板序列 $[a_{i,1}, a_{i,2}, \dots, a_{i,m}]$ 可以与这些块一致。

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.