#P12115. [NWRRC2024] Keyboard Chaos

    ID: 12035 Type: RemoteJudge 2000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>2024Special JudgeICPCNWRRC

[NWRRC2024] Keyboard Chaos

题目描述

Haven't you ever thought that an ordinary flat keyboard is boring, and you can come up with something more interesting?

A little boy named Kevin came up with a keyboard with nn unusual keys. Each key ii initially contains a sequence of letters: Li,1,Li,2,,Li,LiL_{i, 1}, L_{i, 2}, \ldots, L_{i, |L_{i}|}. Some letters in this sequence can be equal. Each letter is one of the first ee lowercase English letters.

Every time key ii is pressed, the first letter of its sequence is typed and immediately moved to the end of the sequence. Thus, the first time key ii is pressed, letter Li,1L_{i, 1} is typed, and the sequence becomes Li,2,,Li,Li,Li,1L_{i, 2}, \ldots, L_{i, |L_{i}|}, L_{i, 1}. The second time key ii is pressed, letter Li,2L_{i, 2} is typed, and the sequence becomes $L_{i, 3}, \ldots, L_{i, |L_{i}|}, L_{i, 1}, L_{i, 2}$, and so on.

For example, suppose that key 11 contains the sequence a\tt{a}, b\tt{b}, a\tt{a}, and key 22 contains the sequence c\tt{c},d\tt{d}. Then, if you press keys 2,1,2,2,1,1,1,22, 1, 2, 2, 1, 1, 1, 2 in this order, the string cadcbaad\tt{cadcbaad} will be typed.

Help Kevin understand how useful his keyboard is, and find the shortest possible string consisting of the first ee lowercase English letters that cannot be typed with such a keyboard from the given initial state.

输入格式

The first line contains two integers nn and ee, denoting the number of keys and the size of the alphabet (1n1001 \le n \le 100; 2e262 \le e \le 26).

The ii-th of the following nn lines consists of characters Li,1,Li,2,,Li,LiL_{i,1}, L_{i,2}, \ldots, L_{i, |L_i|}, denoting the sequence of letters key ii initially contains (1Li101 \le |L_{i}| \le 10). Every character is one of the first ee lowercase English letters.

输出格式

Print the shortest possible string, consisting of the first ee lowercase English letters, that can not be typed using Kevin's keyboard from the initial state. If there are multiple shortest strings, print any of them.

If any string can be typed, print a single string NO\tt{NO} instead.

1 26
win
f
3 3
abc
bca
cab
aa
4 2
aab
bb
a
bab
NO

提示

In the first test, the only strings that can be typed with Kevin's keyboard are prefixes of winwinwinwin...\tt{winwinwinwin...}. Since you can not start the string with any letter other than w\tt{w}, any lowercase English letter except w\tt{w} is a correct answer.

In the second test, bb\tt{bb} and cc\tt{cc} are other possible answers.