#P13142. [GCJ 2018 #1C] A Whole New Word

    ID: 15007 远端评测题 15000ms 1024MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>2018Special Judge字典树 TrieGoogle Code Jam

[GCJ 2018 #1C] A Whole New Word

题目描述

Vincent and Desta are childhood friends. Today, Vincent is showing NN distinct LL-letter words to Desta by using some letter tiles. Each tile contains one uppercase English alphabet letter, and one number between 11 and LL. A word consists of the letters spelled out by LL tiles with numbers from 11 through LL, in order. (Vincent's words are not necessarily real English words.)

For example, if Vincent has N=3N = 3 words with L=4L = 4, and the words are {CAKE,TORN,SHOW}\{\text{CAKE}, \text{TORN}, \text{SHOW}\}, then Vincent must show the following to Desta:

Desta feels that creating words must be easy, and he wants to create a new word that obeys the rules above and is not one of Vincent's existing words. However, Desta does not have any tiles of his own, so he must use some of Vincent's tiles.

For instance, if Vincent has the words from the previous example, then Desta can make a new word such as CORN\text{CORN} or SAKE\text{SAKE} or CHRE\text{CHRE} (Desta's words are also not necessarily real English words). Each of the example is illustrated in the following image:

Note that the three rows in the image above are independent. Desta only needs to make one new word.

However, in the above example, Desta cannot make WAKE, for example, because there is no W\text W tile with a number 11. Nor can he make coo, since it is not the right length.

Notice that it may be impossible for Desta to make a new word. For example, if Vincent has only one word, then Desta cannot make anything new. Or, if Vincent has the words {AA,AB,BA,BB}\{\text{AA}, \text{AB}, \text{BA}, \text{BB}\}, then any word that Desta can form is already present.

Help Desta to choose a word that he can show to Vincent using only the tiles used by Vincent, or indicate that it is impossible to do so.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each begins with one line with two integers NN and LL: the number of Vincent's words, and the length of each word. Then, NN more lines follow. The ii-th of these lines contains a string of LL uppercase English letters representing the ii-th of Vincent's words.

输出格式

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is a valid word to be chosen by Desta, or - (a single dash character of ASCII value 45) if there is no valid word to be chosen by Desta. If there is more than one valid word that Desta can make, you can output any of them.

5
4 1
A
B
C
D
4 2
WW
AA
SS
DD
4 2
AA
AB
BA
BB
3 4
CAKE
TORN
SHOW
5 7
HELPIAM
TRAPPED
INSIDEA
CODEJAM
FACTORY
Case #1: -
Case #2: WA
Case #3: -
Case #4: CORN
Case #5: HOLIDAY

提示

Sample Explanation

Note that the last two sample cases would not appear in test set 1.

In Sample Case #1, the only words that can be constructed using the tiles used by Vincent are A, B, C, D. However, all of those words already appear in Vincent's list of words, so Desta is not allowed to choose them.

In Sample Case #2, there are 1212 possible new words that Desta can make, one of which is WA\text{WA}.

Sample Case #3 was explained in the problem description above; there is no new word that Desta can make.

Sample Case #4 was explained in the problem description above; other answers such as SAKF\text{SAKF} are possible.

In Sample Case #5, other answers such as TRAPJAM\text{TRAPJAM} are possible.

Limits

  • 1T1001 \leqslant T \leqslant 100.
  • No two of Vincent's words are the same.

Test set 1 (11 Pts, Visible)

  • 1N2621 \leqslant N \leqslant 26^{2}.
  • 1L21 \leqslant L \leqslant 2.

Test set 2 (17 Pts, Hidden)

  • 1N20001 \leqslant N \leqslant 2000.
  • 1L101 \leqslant L \leqslant 10.