luogu#P3546. [POI2012] PRE-Prefixuffix

    ID: 7575 远端评测题 1000ms 64MiB 尝试: 2 已通过: 2 难度: 6 上传者: 标签>2012POI哈希HASH前缀和线性递推递推式

[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,S2S_1, S_2,如果能够将 S1S_1 的一个后缀移动到开头后变成 S2S_2,就称 S1S_1S2S_2 循环相同。例如串 ababba 和串 abbaab 是循环相同的。

给出一个长度为 nn 的串 SS,求满足下面条件的最大的 L(Ln2)L(L\leq \frac n 2)SSLL 前缀和 SSLL 后缀是循环相同的。

输入格式

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.

15
ababbabababbaab
6

提示

数据范围:

  • 对于 30%30\% 的数据,保证 n500n\le 500
  • 对于 50%50\% 的数据,保证 n5000n\le 5000
  • 对于 100%100\% 数据,保证 1n1061\le n\le 10^6