IOI '95 Practice Task 2 - Word Chains

View as PDF

Submit solution

Points: 12
Time limit: 0.6s
Memory limit: 8M

Problem type
IOI '95 - Eindhoven, Netherlands

A word consists of at least one and at most 75 lowercase letters (from a to z). A list of one or more words is called a chain when each word in that list, except the first, is obtained from the preceding word by appending one or more letters on the right. For instance, the list

i
in
int
integer

is a chain of four words, but the list

input
integer

is not a chain. Note that every list of one word is a chain.

Input Specification

Your program is given a list of words containing at least one word and all of the words together have no more than 2\,000\,000 letters. The input is terminated with a line containing a single period (.). All other lines contain one word each. The list is sorted lexicographically using the standard alphabetical ordering (as in an English dictionary). There are no duplicate words in the list.

Output Specification

The length of a chain is the number of words it contains. Your program should write to the output a longest chain of words taken from the input. Each word should be on a separate line.

If there is more than one chain of maximum length, your program should output only one of these chains. It does not matter which one.

Sample Input

i
if
in
input
int
integer
output
.

Sample Output

i
in
int
integer

Comments

There are no comments at the moment.