Colliding Encoding

면접 대비

시간 제한20초메모리 제한1024 MB

요약
알파벳을 숫자로 바꾸는 대응과 서로 다른 단어 목록이 주어질 때, 두 단어의 인코딩 결과가 같은 쌍이 있는지 판별한다.
난이도

쉬움10점 중 3점

유형
해시맵, 문자열, 구현
정답자
아직 제출이 없습니다

문제

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 00 through 99. 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 2626 letters in the English alphabet and only 1010 decimal digits. As a result, there might be collisions, that is, pairs of different words whose encoding is the same.

Given a list of N\mathbf{N} 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, T\mathbf{T}. T\mathbf{T} test cases follow.

The first line of each test case contains 2626 decimal digits (integers between 00 and 99, inclusve) D_A,D_B,…,D_Z\mathbf{D\_A}, \mathbf{D\_B}, \dots, \mathbf{D\_Z}, representing the mapping that Alan uses. A letter α\alpha is mapped to digit D_α\mathbf{D\_\alpha}.

The second line of each test case contains N\mathbf{N}, the number of words Alan will encode.

The ii-th of the last N\mathbf{N} lines contains a string S_i\mathbf{S\_i}, representing the ii-th word Alan will encode.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is either YES, if there is at least one pair of different words from the list whose encoding coincides, and NO otherwise.

제한

  • 1≤T≤1001 \le \mathbf{T} \le 100.
  • 0≤D_α≤90 \le \mathbf{D\_\alpha} \le 9, for all α\alpha.
  • 1≤1 \le the length of S_i≤10 \mathbf{S\_i} \le 10, for all ii.
  • Each character of S_i\mathbf{S\_i} is an uppercase English letter A through Z, for all ii.
  • S_i≠S_j\mathbf{S\_i} \ne \mathbf{S\_j}, for all i≠ji \ne j.

힌트

In Sample Case #1, the mapping for A is 00, for B is 11, for C is 22, for D is 33, and for E is 33. With this mapping, ABC is encoded as 012012, BC is encoded as 1212, BCD as 123123, and CDE as 233233. Since all of these encodings are distinct, there are no collisions.

In Sample Case #2, the mapping for C is 22, for D is 33, for E is 33, for F is 33, and for G is 33. With this mapping, CDE is encoded as 233233, DEF as 333333, and EFG as 333333. Since the encoding for DEF and EFG is the same, there is a collision.

예제1

  1. 예제 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
    
    예상 출력
    Case #1: NO
    Case #2: YES