QOJ.ac

QOJ

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

#12493. 碰撞编码

الإحصائيات

Alan 今天刚上了他人生中的第一堂密码学课。他决定学以致用,设计一套属于他自己的密码。他会将每一个英文字母从 A 到 Z 映射为一个 0 到 9 之间的十进制数字。然后,他会尝试通过将单词中的每个字母替换为其对应的映射数字,将每个单词编码为一个由十进制数字组成的字符串。

Alan 兴奋之余忽略了一点:英文字母表中有 26 个字母,而十进制数字只有 10 个。因此,可能会出现冲突,即存在两个不同的单词,它们的编码相同。

给定一个 Alan 想要编码的单词列表以及他所使用的映射方案,你能找出列表中是否存在单词间的冲突吗?

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 组测试用例。 每个测试用例的第一行包含 26 个十进制数字(均为 0 到 9 之间的整数,包含 0 和 9),表示 Alan 使用的映射方案。字母 $\alpha$ 被映射为数字 $D_{\alpha}$。 每个测试用例的第二行包含 $N$,即 Alan 要编码的单词数量。 接下来的 $N$ 行中,第 $i$ 行包含一个字符串 $S_i$,表示 Alan 要编码的第 $i$ 个单词。

输出格式

对于每个测试用例,输出一行 Case #x: y,其中 $x$ 是测试用例编号(从 1 开始),如果列表中至少有一对不同的单词编码相同,则 $y$ 为 YES,否则为 NO

数据范围

$1 \le T \le 100$。 $0 \le D_{\alpha} \le 9$,对于所有 $\alpha$。 $1 \le |S_i| \le 10$,对于所有 $i$。 $S_i$ 的每个字符均为大写英文字母 A 到 Z,对于所有 $i$。 $S_i \neq S_j$,对于所有 $i \neq j$。

子任务

测试集 1(可见判决) $1 \le N \le 100$。

测试集 2(可见判决) $1 \le N \le 6 \times 10^4$。

样例

样例输入 1

2
0 1 2 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
4
ABC
BC
BCD
CDE
0 1 2 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
3
CDE
DEF
EFG

样例输出 1

Case #1: NO
Case #2: YES

说明

在样例 1 中,A 映射为 0,B 映射为 1,C 映射为 2,D 映射为 3,E 映射为 3。使用此映射,ABC 编码为 012,BC 编码为 12,BCD 编码为 123,CDE 编码为 233。由于所有编码均不相同,因此没有冲突。

在样例 2 中,C 映射为 2,D 映射为 3,E 映射为 3,F 映射为 3,G 映射为 3。使用此映射,CDE 编码为 233,DEF 编码为 333,EFG 编码为 333。由于 DEF 和 EFG 的编码相同,因此存在冲突。

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.