QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 256 MB 总分: 100

#11810. 被禁用的模式

统计

新的审查法案已经通过,大量字符和字符串被明确禁止出现在公开出版物中。

具体来说,有 $N$ 个模式串被列入黑名单。为简化问题,我们仅考虑大写字母,且每个模式串仅由大写字母组成。

当局全面禁止那些包含至少一个与黑名单模式串匹配的子串的字符串。

如果一个子串可以通过选择 26 个大写字母的某种置换转换为某个模式串,则称该匹配满足正确性。以下列出了一些示例: ABB、ACC、BAA、UTT、XZZ 和 ZAA 两两匹配。 ABCDECBA 与 TYQAXQYT 匹配,但不与 QWEWSEWQ 匹配。

你需要设计一个高效的算法来判断即将出版的刊物是否合法。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 20$),表示测试用例的数量。

对于每个测试用例,第一行是禁止模式串的数量 $N$ ($1 \le N \le 5000$)。

接下来的 $N$ 行,每行包含一个由大写字母组成的模式串。

第 $(N + 2)$ 行包含一个整数 $M$ ($1 \le M \le 250000$),表示需要根据上述模式串进行判断的字符串数量。

接下来的 $M$ 行,每行包含一个由大写字母组成的字符串。

每个测试用例中,所有模式串的总长度不超过 $100000$,所有待判断字符串的总长度不超过 $1000000$。

输出格式

对于每个测试用例,输出一行,包含测试用例编号和 $M$ 个字母。然后对于每个给定的字符串,如果它是被禁止的,输出 “Y”,否则输出 “N”。

样例

输入格式 1

2
2
AAB
ABB
8
TUU
ZZY
UVW
ABABABA
UUVV
TTUUO
EEEE
XY
1
ABCBD
5
UVWXY
UVVVY
UVWVY
YVWVY
VVWVY

输出格式 1

Case #1: Y Y N N Y Y N N
Case #2: N N Y N N

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.