Repeats
Time limit6sMemory limit512 MB
Given a binary string of length n, find a substring that is some seed repeated as many times as possible, and report the count, seed length, and 1-based start position.
- Level
Hard8 of 10
- Topics
- String, String matching, Sorting, Binary search
- Solved
- No attempts yet
Problem
A string is called a -repeat if is obtained by concatenating copies of some seed string of length . For example, the string
s = abaabaabaaba
is a -repeat with seed string
t = aba
That is, the seed string has length 3, and the whole string is obtained by repeating four times.
Write a program for the following task. The input is a long string consisting of the characters ‘a’ and ‘b’. The program must find a -repeat that occurs as a substring of with as large as possible. For example, the input string
u = babbabaabaabaabab
contains the -repeat starting at position 5. Since contains no other contiguous substring with more than 4 repeats, the program must output this substring.
Input
The first line contains one integer, the length of the input string ().
The next lines contain the input string, one character (‘a’ or ‘b’) per line, in order.
Output
The output consists of three integers, each on its own line. They report the -repeat your program found as follows.
- The first line contains the repeat count that is maximized.
- The second line contains the length of the seed string that is repeated times.
- The third and final line contains the position at which the -repeat starts ().
If the given input has several answers with the same , your program may report any one of them.
Hint
A -repeat starts at the 5th character of the input string (line 6 of the input).