Central String

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

요약
길이가 같은 N개의 문자열과 거리 한계 D가 주어질 때, 모든 문자열과 해밍 거리가 D 이하인 문자열이 존재하는지 판정하고 그런 문자열 하나를 출력한다.
난이도

보통10점 중 7점

유형
문자열, 완전 탐색, 구현, 조합론
정답자
아직 제출이 없습니다

문제

You have a collection of strings of the same length LL and are wondering how similar they are. We can say that the distance d(S,T)d(S,T) between two strings SS and TT of the same length is the number of indices ii where S_i≠T_iS\_ i \neq T\_ i. For example, d(d(berry, bears)=2) = 2 since only the third and fifth characters differ.

You wonder if your strings are very close to each other. That is, for a given distance DD you have in mind, is there a string SS of length LL such that d(S,A)≤Dd(S,A) \leq D for each string AA in your collection? Call such a string SS a central string. Note that a central string does not necessarily have to be one of your strings.

입력

The first line of input contains three integers NN (1≤N≤501 \leq N \leq 50), LL (1≤L≤1,000,0001 \leq L \leq 1\\, 000\\, 000), and DD (0≤D≤60 \leq D \leq 6). Here, NN indicates the number of strings in your collection, LL is the common length of these strings, and DD is the distance bound you are curious about. Then NN lines follow, the ii’th such line contains a single string A_iA\_ i of length LL consisting of only lowercase letters.

You are further guaranteed that N⋅L≤1,000,000N \cdot L \leq 1\\, 000\\, 000.

출력

Output consists of a single line. If there is a string SS consisting of only lowercase letters such that d(S,A_i)≤Dd(S,A\_ i) \leq D for each 1≤i≤N1 \leq i \leq N, output any such string. Otherwise, simply output the single digit 0 to indicate there is no central string.

예제3

  1. 예제 1

    입력
    2 4 1
    abba
    bbca
    
    예상 출력
    abca
    
  2. 예제 2

    입력
    3 4 3
    abcd
    efgh
    ijkl
    
    예상 출력
    abgl
    
  3. 예제 3

    입력
    3 4 2
    abcd
    efgh
    ijkl
    
    예상 출력
    0