Logo HelloWorld信息学奥赛题库

少儿编程

时间限制:1 s 空间限制:256 MB

#2034. [POI2012]PRE-Prefixuffix

统计

题目描述

We consider strings consisting of lowercase letters of the English alphabet in this problem.
An initial fragment of a given string is called its prefix.
A final (terminal) fragment of a given string is called its suffix.
In particular, the empty string is both a prefix and a suffix of any string.
Two strings are cyclically equivalent if one of them can be obtained from another by moving its certain suffix from the end of the string to its beginning.
For example, the strings  and  are cyclically equivalent, whereas the strings  and  are not.
In particular, every string is cyclically equivalent to itself.
A string  consisting of  letters is given.
We are looking for its prefix  and suffix  of equal length such that:
 and  are cyclically equivalent, the common length of  and  does not exceed  (i.e., the prefix  and the suffix  do not overlap in ), and the common length of  and  is maximized.
对于两个串S1、S2,如果能够将S1的一个后缀移动到开头后变成S2,就称S1和S2循环相同。例如串ababba和串abbaab是循环相同的。
给出一个长度为n的串S,求满足下面条件的最大的L:
S的L前缀和S的L后缀是循环相同的。

输入格式:

The first line of the standard input contains a single integer  () denoting the length of the string .
The second line of input contains the string  itself, consisting of  lowercase letters of the English alphabet.
In tests worth 30% of the points the condition  holds in addition.
In tests worth 50% of the points the condition  holds in addition.

输出格式:

Your program should print a single integer in the first and only line of the standard output, namely the common length of the prefix  and the suffix  that we are looking for.

输入样例#1:

15
ababbabababbaab

输出样例#1:

6