Typing Practice
InterviewTime limit8sMemory limit1024 MB
Given up to six strings over the letters A to D, find the shortest string that contains every input string as a subsequence, breaking ties lexicographically.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Bit manipulation, BFS, String
- Solved
- No attempts yet
Problem
Mingyu and Myeongjin are having a typing practice contest. The typing practice consists of words, and each word is made up only of the uppercase letters A through D. Starting from the first letter of a word, typing the correct letter for the current position advances to the next letter, and after typing all the letters, pressing Enter moves on to the next word. Because the program is forgiving of typos, typing a wrong letter is simply ignored with no penalty. In other words, viewing the words as sequences, a word is typed successfully if the given word is a subsequence of the word formed by collecting the typed letters.
Mingyu, unable to beat Myeongjin due to lack of skill, decides to cheat. Discovering that the program is lax enough to allow pasting, he plans to create a single word and keep pasting it to pass through all the words in an instant. That is, viewing the words as sequences, Mingyu's word must have all words as subsequences. Since his typing speed is slow, he wants the length of that word to be minimal. Write a program to find the word Mingyu should use.
Input
The first line gives the number of words .
Over the following lines, the strings representing the typing practice words are given. consists only of the uppercase letters A, B, C, D and has length at most .
Output
Print the string to use on the first line. If there are several possible strings, print the lexicographically smallest one.