아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Multidimensional Hangman

면접 대비

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

요약
보드의 각 단어에는 한 위치만 미지 문자이고, 가장 많은 단어와 호환되는 단어를 사전순으로 가장 작게 찾는다.
난이도

보통10점 중 5점

유형
해시맵, 완전 탐색, 구현
정답자
아직 제출이 없습니다

문제

The Multidimensional Hangman Game has very peculiar rules. In a way, it is like you are playing several games of the traditional Hangman game at the same time, with the difference that the words don’t have to exist in the dictionary. If you’ve never played Hangman, don’t worry: all the information you need is below.

In the multidimensional version of the game, there are several words on a board, initially unknown, all of the same length. At each turn in the game, you discover some characters from certain word positions (how these characters were discovered is not important for this problem). At a certain point, when only one unknown character remains in each word on the board, the game goes into the all or nothing phase. At this point, you must choose a word that maximizes the number of compatibilities with the words on the board. For a chosen word PP, we say it is compatible with a word TT on the board if all known letters in TT occur in exactly the same positions in PP.

Given the known information about the words on the board, you must determine which word to choose for all or nothing phase, which maximizes the number of compatibilities. If there is more than one solution, print the lexicographically smallest. We say that a word PP is lexicographically smaller than a word QQ if P_i<Q_iP\_i < Q\_i where P_iP\_i is the ii-th character of PP, Q_iQ\_i is the ii-th character of QQ and ii is the smallest index such that P_i≠Q_iP\_i \ne Q\_i.

입력

The first line of the input contains two integers NN and CC satisfying 1≤N≤1041 ≤ N ≤ 10^4 and 1≤C≤121 ≤ C ≤ 12, indicating the number of words on the board and the length of the words it contains. Each of the next NN lines contains a word of length CC composed only of characters from “a” to “z” except for one of its positions, which will contain a character “*” , indicating that the character at that position is still unknown.

출력

Print a single line, containing, in order, a word TT, of length CC, and an integer MM, such that MM is the greatest number of compatibilities a word might have with the input words and TT is the lexicographically smallest amongst the words with compatibility MM.

예제2

  1. 예제 1

    입력
    5 4
    rat*
    ru*d
    rot*
    r*ta
    r*ta
    
    예상 출력
    rata 3
    
  2. 예제 2

    입력
    5 4
    bon*
    fon*
    n*no
    *eto
    *ano
    
    예상 출력
    nano 2