304643: CF886D. Restoration of string
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Restoration of string
题意翻译
如果一个字符串的子串出现的次数大于任何子串出现的次数,那么这个子串就是 $\text{most frequent}$。 给 $n$ 个 $\text{most frequent}$ 子串,问最短的原串。 如果有多个最短原串,取字典序最小的那个。没有就输出 `NO`。题目描述
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Restore the non-empty good string with minimum length. If several such strings exist, restore lexicographically minimum string. If there are no good strings, print "NO" (without quotes). A substring of a string is a contiguous subsequence of letters in the string. For example, "ab", "c", "abc" are substrings of string "abc", while "ac" is not a substring of that string. The number of occurrences of a substring in a string is the number of starting positions in the string where the substring occurs. These occurrences could overlap. String $ a $ is lexicographically smaller than string $ b $ , if $ a $ is a prefix of $ b $ , or $ a $ has a smaller letter at the first position where $ a $ and $ b $ differ.输入输出格式
输入格式
The first line contains integer $ n $ ( $ 1<=n<=10^{5} $ ) — the number of strings in the set. Each of the next $ n $ lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct. The total length of the strings doesn't exceed $ 10^{5} $ .
输出格式
Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings.
输入输出样例
输入样例 #1
4
mail
ai
lru
cf
输出样例 #1
cfmailru
输入样例 #2
3
kek
preceq
cheburek
输出样例 #2
NO