QOJ.ac

QOJ

时间限制: 1 s 内存限制: 32 MB 总分: 10

#11660. 保险箱

统计

ByteGuy 拥有一个带锁的保险箱。这个锁有 $n$ 个旋钮。每个旋钮可以处于 $p$ 个可能位置中的一个。

ByteGuy 已经很久没有使用他的保险箱了,因此他忘记了打开保险箱的旋钮配置。他去了生产锁的公司,了解了锁的构造。它由 $n$ 个旋钮和相同数量的锁栓组成。它们(锁栓和旋钮)都可以处于 $0$ 到 $p - 1$ 编号的 $p$ 个允许位置之一。当所有锁栓都设置为位置 $0$ 时,锁就会打开。将第 $i$ 个旋钮转动一个位置(从位置 $0$ 到 $1$,从 $1$ 到 $2$,……,从 $p - 2$ 到 $p - 1$,从 $p - 1$ 到 $0$)会导致第 $j$ 个锁栓转动 $c_{i,j}$ 个位置(从位置 $l$ 到 $(l + c_{i,j}) \bmod p$)。锁的制造商帮助了 ByteGuy,给了他一台现代化的 3D 扫描仪,这使得他可以检查隐藏在保险箱内的锁栓配置。

为保险箱制造的锁质量很高,并且只有一种旋钮配置可以打开锁。

任务

编写一个程序,完成以下工作:

  • 读取 ByteGuy 保险箱中锁的描述,
  • 计算打开锁的旋钮配置,
  • 将结果写入标准输出。

输入格式

第一行包含两个整数 $n$(旋钮的数量,$1 \le n \le 300$)和质数 $p$(旋钮可能位置的数量,$3 \le p \le 40\,000$)。下一行包含 $n$ 个范围在 $0 \ldots p - 1$ 之间的整数,表示各个旋钮当前所处的位置。第三行包含 $n$ 个范围在 $0 \ldots p - 1$ 之间的整数,表示 ByteGuy 保险箱中各个锁栓当前的位置。接下来的 $n$ 行包含各个旋钮的描述——其中第 $i$ 行包含 $n$ 个整数 $c_{i,0}, c_{i,1}, \ldots, c_{i,n-1}$,其中 $0 \le c_{i,j} < p$。

输出格式

输出一行,包含 $n$ 个范围在 $0 \ldots p - 1$ 之间的整数,用空格分隔,表示打开锁的旋钮配置。

样例

输入 1

2 3
1 1
2 2
1 0
0 1

输出 1

2 2

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.