CF1739F.Keyboard Design

普及/提高-

通过率:0%

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.

输入格式

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

Then, nn lines follow. The ii -th of them contains an integer cic_i ( 1ci1051 \le c_i \le 10^5 ) and a string sis_i ( 2si20002 \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,si1]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=1nsi2000\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.

输入输出样例

  • 输入#1

    3
    7 abacaba
    10 cba
    4 db

    输出#1

    hjkildbacefg
  • 输入#2

    1
    100 abca

    输出#2

    abcdefghijkl
首页