Richelieu's Parades
Time limit2sMemory limit1024 MB
For each j, delete one length-j substring from t and find the most rows s_i whose prefix is the remaining string. Print the maximum for every j.
- Level
Hard8 of 10
- Topics
- String matching, Trie, String
- Solved
- No attempts yet
Problem
Cardinal Richelieu decided to line up his guards today. The parade ground has rows. Each guard in a row wears a uniform of some color. There are 26 uniform colors, and each color is denoted by its own letter of the Latin alphabet.
Each row is given by a string . The start of the string is the front of the row, and the end of the string is the back of the row.
Several demonstration parades are planned. Richelieu has a string that he uses to build each parade. There will be parades in total, held as follows. For the -th parade, Richelieu deletes one substring of length from and calls the remaining string . Then he selects every row whose prefix equals , and those rows take part in the -th parade.
Input
The first line contains a string () made of lowercase Latin letters.
The next line contains two positive integers and (, ), where is the number of rows and is the number of parades.
Each of the following lines contains a row string . It is non-empty and made of lowercase Latin letters.
The total length of all does not exceed .
Output
Print integers on a single line. The -th number is the maximum number of rows that can take part in the -th parade.