#P9694. [GDCPC 2023] New but Nostalgic Problem
[GDCPC 2023] New but Nostalgic Problem
题目描述
Given strings , please select strings among them, so that the lexicographic order of string is minimized, and output the optimal string . String satisfies the following constraint: is the longest common prefix of two selected strings with different indices. Also, is the lexicographically largest string among all strings satisfying the constraint.
More formally, let be a set of size , where all the elements in the set are integers between and (both inclusive) and there are no duplicated elements. Let be the longest common prefix of string and , please find a set to minimize the lexicographic order of the following string and output the optimal string .
$$v = \max\limits_{i \in \mathbb{S}, j \in \mathbb{S}, i \ne j} \text{lcp}(w_i, w_j) $$In the above expression, is calculated by comparing the lexicographic order of strings.
Recall that:
- String is a prefix of string , if we can append some number of characters (including zero characters) at the end of so that it changes to . Specifically, empty string is a prefix of any string.
- The longest common prefix of string and string is the longest string such that is a prefix of both and . For example, the longest common prefix of
abcdeandabcefisabc, while the longest common prefix ofabcdeandbcdefis an empty string. - String is lexicographically smaller than string (), if
- is a prefix of , or
- , where is the longest common prefix of and , is the length of , is the -th character of string , and is the -th character of string .
- Specifically, empty string is the string with the smallest lexicographic order.
输入格式
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains two integers and (, ) indicating the total number of strings and the number of strings to be selected.
For the following lines, the -th line contains a string () consisting of lower-cased English letters.
It's guaranteed that the total length of all strings of all test cases will not exceed .
输出格式
For each test case output one line containing one string indicating the answer. Specifically, if the answer is an empty string, print .
2
5 3
gdcpc
gdcpcpcp
suasua
suas
sususua
3 3
a
b
c
gdcpc
EMPTY