CF1739F.Keyboard Design

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Monocarp has a dictionary of nn words, consisting of 1212 first letters of the Latin alphabet. The words are numbered from 11 to nn. In every pair of adjacent characters in each word, the characters are different. For every word ii, Monocarp also has an integer cic_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 1212 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 cic_i over all words ii that can be typed easily with it.

Help Monocarp to design a keyboard with the maximum possible optimality.

Monocarp 拥有一个包含 nn 个单词的词典,这些单词仅由拉丁字母表的前 1212 个字母(即 a 到 l)组成。这些单词编号为 11 至 nn。在每个单词中,任意两个相邻字符均不相同。

对于每个单词 ii,Monocarp 还拥有一个整数 cic_i,表示他使用该单词的频率。

Monocarp 希望设计一款键盘,使得他能便捷地输入其中一部分单词。键盘可表示为一个长度为 1212 的序列,恰好包含字母 a 到 l 各一次。

若一个单词中每一对相邻字符在键盘序列中也彼此相邻,则称该单词可被此键盘“便捷输入”。键盘的“最优性”定义为:所有可被便捷输入的单词 ii 对应的 cic_i 值之和。

请帮助 Monocarp 设计一个具有最大可能最优性的键盘。

输入格式

The first line contains one integer nn (1≤n≤10001 \le n \le 1000) — the number of words.

Then, nn lines follow. The ii-th of them contains an integer cic_i (1≤ci≤1051 \le c_i \le 10^5) and a string sis_i (2≤∣si∣≤20002 \le |s_i| \le 2000) denoting the ii-th word. Each character of sis_i is one of 1212 first letters of Latin alphabet, in lowercase. For every j∈[1,∣si∣−1]j \in [1, |s_i| - 1], the jj-th character of sis_i is different from the (j+1)(j+1)-th one.

Additional constraint on the input: ∑i=1n∣si∣≤2000\sum \limits_{i=1}^{n} |s_i| \le 2000.

第一行包含一个整数 nn(1≤n≤10001 \le n \le 1000)—— 表示单词的数量。

接下来有 nn 行。其中第 ii 行包含一个整数 cic_i(1≤ci≤1051 \le c_i \le 10^5)和一个字符串 sis_i(2≤∣si∣≤20002 \le |s_i| \le 2000),表示第 ii 个单词。sis_i 的每个字符均为拉丁字母表前 1212 个小写字母之一。对每个 j∈[1,∣si∣−1]j \in [1, |s_i| - 1],sis_i 的第 jj 个字符与第 (j+1)(j+1) 个字符不同。

输入的额外约束:∑i=1n∣si∣≤2000\sum \limits_{i=1}^{n} |s_i| \le 2000。

输出格式

Print a sequence of 1212 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.

输出拉丁字母表的前 1212 个字母构成的一个序列,其中每个字母 a 到 l 恰好出现一次,表示最优键盘布局。如果存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    7 abacaba
    10 cba
    4 db

    输出#1

    hjkildbacefg
  • 输入#2

    1
    100 abca

    输出#2

    abcdefghijkl

输入解题思路,AI测评打分。不知道怎么写?

首页