CF1739F.Keyboard Design
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Monocarp has a dictionary of n words, consisting of 12 first letters of the Latin alphabet. The words are numbered from 1 to n . In every pair of adjacent characters in each word, the characters are different. For every word i , Monocarp also has an integer ci denoting how often he uses this word.
Monocarp wants to design a keyboard that would allow him to type some of the words easily. A keyboard can be denoted as a sequence of 12 first letters of the Latin alphabet, where each letter from a to l appears exactly once.
A word can be typed with the keyboard easily if, for every pair of adjacent characters in the word, these characters are adjacent in the keyboard as well. The optimality of the keyboard is the sum of ci over all words i that can be typed easily with it.
Help Monocarp to design a keyboard with the maximum possible optimality.
输入格式
The first line contains one integer n ( 1≤n≤1000 ) — the number of words.
Then, n lines follow. The i -th of them contains an integer ci ( 1≤ci≤105 ) and a string si ( 2≤∣si∣≤2000 ) denoting the i -th word. Each character of si is one of 12 first letters of Latin alphabet, in lowercase. For every j∈[1,∣si∣−1] , the j -th character of si is different from the (j+1) -th one.
Additional constraint on the input: i=1∑n∣si∣≤2000 .
输出格式
Print a sequence of 12 first letters of the Latin alphabet, where each letter from a to l appears exactly once, denoting the optimal keyboard. If there are multiple answers, you may print any of them.
输入输出样例
输入#1
3 7 abacaba 10 cba 4 db
输出#1
hjkildbacefg
输入#2
1 100 abca
输出#2
abcdefghijkl