Longest Substring
Time limit5sMemory limit1024 MB
For each k from 1 to n, find the longest substring that occurs exactly k times and allows the most non-overlapping occurrences, then print the lengths.
- Level
Hard8 of 10
- Topics
- String matching, Tree
- Solved
- No attempts yet
Problem
For a string of length and a positive integer (), a non-empty substring of is called a -substring if the substring appears exactly times. These occurrences may overlap. For example, if "ababa", the -substrings of for every are as follows.
- There are four -substrings in : "abab", "ababa", "bab", and "baba", because each appears exactly once. "aba" is not a -substring because it appears twice.
- There are four -substrings: "ab", "aba", "b", and "ba". "ab" appears exactly twice without overlapping. The two occurrences of "aba" overlap at the character "a", and it does not appear three times.
- There is only one -substring, "a".
- There are no -substrings or -substrings.
For a -substring of , let be the maximum number of disjoint occurrences of in . For example, "ab" can be selected twice without overlapping, so . For the -substring "aba", , because two of its occurrences cannot be chosen without overlapping. For the -substring "a", .
Let be the length of the longest -substring among those with the largest , for . For "ababa", , , , and .
Input
The input is a single line containing the string of length (), consisting of lowercase English letters.
Output
Print exactly one line with nonnegative integers separated by spaces: . If there is no -substring for some , then is .