#P17214. [ICPC 2017 Nanning R] Banned Patterns
[ICPC 2017 Nanning R] Banned Patterns
Problem Description
:::align{center}
:::
The new censorship law has been passed and a mass of characters and strings are explicitly prohibited appearing in the public publication.
Specifically, patterns were blacklisted. To simplify the problem, we only consider the uppercase letters and each pattern is a string that consists of only uppercase letters.
The authority makes a total ban on those strings which have at least one substring matching a banned pattern.
If a substring can be transmuted to a pattern by choosing a permutation of all uppercase letters, the matching satisfies the correctness. Here we list some examples.
Each two of , , , , and match each other.
matches but does not match .
You aim to design an efficient algorithm to judge the validity of upcoming publications.
Input Format
The first line contains a number indicating the number of test cases.
For each test case, the first line is the number of banned patterns .
Each of the following lines contains a pattern in capital letters.
The -th line contains an integer which is the number of strings asked to be judged based on above patterns.
Each of the following lines consists a string in capital letters as well.
The total length of patterns in a test case should not be larger than , and the total length of strings asked to be judged should not be larger than .
Output Format
For each test case, output a line with the index and letters. Then for each given string, output “Y” if it is prohibited, or “N” if it is allowed.
2
2
AAB
ABB
8
TUU
ZZY
UVW
ABABABA
UUVV
TTUUO
EEEE
XY
1
ABCBD
5
UVWXY
UVVVY
UVWVY
YVWVY
VVWVY
Case #1: Y Y N N Y Y N N
Case #2: N N Y N N