A12074. String Journey
编程题
普及/提高-
知识点
题目描述
We call a sequence of strings $t_{1},...,t_{k}$ a journey of length $k$ , if for each $i>1$ $t_{i}$ is a substring of $t_{i-1}$ and length of $t_{i}$ is strictly less than length of $t_{i-1}$ . For example, ${ab,b}$ is a journey, but ${ab,c}$ and ${a,a}$ are not.
Define a journey on string $s$ as journey $t_{1},...,t_{k}$ , such that all its parts can be nested inside $s$ in such a way that there exists a sequence of strings $u_{1},...,u_{k+1}$ (each of these strings can be empty) and $s=u_{1}t_{1}u_{2}t_{2}...\ u_{k}t_{k}u_{k+1}$ . As an example, ${ab,b}$ is a journey on string $abb$ , but not on $bab$ because the journey strings $t_{i}$ should appear from the left to the right.
The length of a journey on a string is the number of strings in it. Determine the maximum possible length of a journey on the given string $s$ .
Define a journey on string $s$ as journey $t_{1},...,t_{k}$ , such that all its parts can be nested inside $s$ in such a way that there exists a sequence of strings $u_{1},...,u_{k+1}$ (each of these strings can be empty) and $s=u_{1}t_{1}u_{2}t_{2}...\ u_{k}t_{k}u_{k+1}$ . As an example, ${ab,b}$ is a journey on string $abb$ , but not on $bab$ because the journey strings $t_{i}$ should appear from the left to the right.
The length of a journey on a string is the number of strings in it. Determine the maximum possible length of a journey on the given string $s$ .
输入格式
The first line contains a single integer $n$ ( $1<=n<=500000$ ) — the length of string $s$ .
The second line contains the string $s$ itself, consisting of $n$ lowercase Latin letters.
The second line contains the string $s$ itself, consisting of $n$ lowercase Latin letters.
输出格式
Print one number — the maximum possible length of string journey on $s$ .
输入输出样例
输入 #1
7 abcdbcc
输出 #1
3
输入 #2
4 bbcb
输出 #2
2
说明/提示
In the first sample, the string journey of maximum length is ${abcd,bc,c}$ .
In the second sample, one of the suitable journeys is ${bb,b}$ .
In the second sample, one of the suitable journeys is ${bb,b}$ .