Short message 4
InterviewTime limit1sMemory limit1024 MB
Build the shortest lowercase string that contains every given planet name as a substring.
- Level
Medium6 of 10
- Topics
- String, Dynamic programming, Bit manipulation, String matching
- Solved
- No attempts yet
Problem
The Space Exploration Center has identified planets, each with a name made up only of lowercase Latin letters. The center's researchers believe that if any of these planets has intelligent life, its inhabitants will reply to a message that contains the planet's name.
Sending cosmic messages is expensive, so the goal is to build a message as short as possible that contains the names of all planets as substrings.
A string is a substring of a string if can be obtained from by deleting some characters from the beginning and the end of .
Input
The first line contains the number of planets . Each of the next lines contains one planet name .
Output
Print one line containing a message made up only of lowercase Latin letters. The message must contain every planet name from the input as a substring.