Multidimensional Hangman
면접 대비시간 제한1초메모리 제한1024 MB
보드의 각 단어에는 한 위치만 미지 문자이고, 가장 많은 단어와 호환되는 단어를 사전순으로 가장 작게 찾는다.
문제
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 , we say it is compatible with a word on the board if all known letters in occur in exactly the same positions in .
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 is lexicographically smaller than a word if where is the -th character of , is the -th character of and is the smallest index such that .
입력
The first line of the input contains two integers and satisfying and , indicating the number of words on the board and the length of the words it contains. Each of the next lines contains a word of length 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 , of length , and an integer , such that is the greatest number of compatibilities a word might have with the input words and is the lexicographically smallest amongst the words with compatibility .