CF1739F.Keyboard Design
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:1024MB
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.
Monocarp 拥有一个包含 n 个单词的词典,这些单词仅由拉丁字母表的前 12 个字母(即 a 到 l)组成。这些单词编号为 1 至 n。在每个单词中,任意两个相邻字符均不相同。
对于每个单词 i,Monocarp 还拥有一个整数 ci,表示他使用该单词的频率。
Monocarp 希望设计一款键盘,使得他能便捷地输入其中一部分单词。键盘可表示为一个长度为 12 的序列,恰好包含字母 a 到 l 各一次。
若一个单词中每一对相邻字符在键盘序列中也彼此相邻,则称该单词可被此键盘“便捷输入”。键盘的“最优性”定义为:所有可被便捷输入的单词 i 对应的 ci 值之和。
请帮助 Monocarp 设计一个具有最大可能最优性的键盘。
输入格式
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.
第一行包含一个整数 n(1≤n≤1000)—— 表示单词的数量。
接下来有 n 行。其中第 i 行包含一个整数 ci(1≤ci≤105)和一个字符串 si(2≤∣si∣≤2000),表示第 i 个单词。si 的每个字符均为拉丁字母表前 12 个小写字母之一。对每个 j∈[1,∣si∣−1],si 的第 j 个字符与第 (j+1) 个字符不同。
输入的额外约束: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.
输出拉丁字母表的前 12 个字母构成的一个序列,其中每个字母 a 到 l 恰好出现一次,表示最优键盘布局。如果存在多个答案,输出任意一个即可。
输入输出样例
输入#1
3 7 abacaba 10 cba 4 db
输出#1
hjkildbacefg
输入#2
1 100 abca
输出#2
abcdefghijkl
输入解题思路,AI测评打分。不知道怎么写?