Colliding Encoding
면접 대비시간 제한20초메모리 제한1024 MB
알파벳을 숫자로 바꾸는 대응과 서로 다른 단어 목록이 주어질 때, 두 단어의 인코딩 결과가 같은 쌍이 있는지 판별한다.
문제
Alan just had his first cryptography class in school today. He decided to apply what he learned and come up with his own cipher. He will map each English letter from A to Z to a decimal digit through . He will then try to encode each word to a string consisting of decimal digits by replacing each letter in the word with its mapped digit.
In his excitement, Alan failed to notice that there are letters in the English alphabet and only decimal digits. As a result, there might be collisions, that is, pairs of different words whose encoding is the same.
Given a list of words that Alan wants to encode and the mapping that he uses, can you find out if there would be any collisions between words on the list?
입력
The first line of the input gives the number of test cases, . test cases follow.
The first line of each test case contains decimal digits (integers between and , inclusve) , representing the mapping that Alan uses. A letter is mapped to digit .
The second line of each test case contains , the number of words Alan will encode.
The -th of the last lines contains a string , representing the -th word Alan will encode.
출력
For each test case, output one line containing Case #x: y, where is the test case number (starting from 1) and is either YES, if there is at least one pair of different words from the list whose encoding coincides, and NO otherwise.
제한
- .
- , for all .
- the length of , for all .
- Each character of is an uppercase English letter
AthroughZ, for all . - , for all .
힌트
In Sample Case #1, the mapping for A is , for B is , for C is , for D is , and for E is . With this mapping, ABC is encoded as , BC is encoded as , BCD as , and CDE as . Since all of these encodings are distinct, there are no collisions.
In Sample Case #2, the mapping for C is , for D is , for E is , for F is , and for G is . With this mapping, CDE is encoded as , DEF as , and EFG as . Since the encoding for DEF and EFG is the same, there is a collision.