A15408 | Keyboard Design
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $c_i$ 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 $c_i$ over all words $i$ that can be typed easily with it.
Help Monocarp to design a keyboard with the maximum possible optimality.
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 $c_i$ 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 \le n \le 1000$ ) — the number of words.
Then, $n$ lines follow. The $i$ -th of them contains an integer $c_i$ ( $1 \le c_i \le 10^5$ ) and a string $s_i$ ( $2 \le |s_i| \le 2000$ ) denoting the $i$ -th word. Each character of $s_i$ is one of $12$ first letters of Latin alphabet, in lowercase. For every $j \in [1, |s_i| - 1]$ , the $j$ -th character of $s_i$ is different from the $(j+1)$ -th one.
Additional constraint on the input: $\sum \limits_{i=1}^{n} |s_i| \le 2000$ .
Then, $n$ lines follow. The $i$ -th of them contains an integer $c_i$ ( $1 \le c_i \le 10^5$ ) and a string $s_i$ ( $2 \le |s_i| \le 2000$ ) denoting the $i$ -th word. Each character of $s_i$ is one of $12$ first letters of Latin alphabet, in lowercase. For every $j \in [1, |s_i| - 1]$ , the $j$ -th character of $s_i$ is different from the $(j+1)$ -th one.
Additional constraint on the input: $\sum \limits_{i=1}^{n} |s_i| \le 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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted