CF1063F.String Journey
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
我们称一个字符串序列 t1,…,tk 为长度为 k 的旅程(journey),当且仅当对每个 i>1,ti 是 ti−1 的子串,且 ti 的长度严格小于 ti−1 的长度。例如,{ab,b} 是一个旅程,但 {ab,c} 和 {a,a} 不是。
定义字符串 s 上的一个旅程为一个旅程 t1,…,tk,使得其所有组成部分均可嵌套于 s 中:即存在一个字符串序列 u1,…,uk+1(其中每个 ui 可为空),满足
s=u1t1u2t2…uktkuk+1.
例如,{ab,b} 是字符串 abb 上的一个旅程,但不是字符串 bab 上的旅程,因为旅程中的字符串 ti 必须从左到右依次出现。
一个字符串上旅程的长度即为其所含字符串的个数。请确定给定字符串 s 上可能的旅程的最大长度。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 500 000) — the length of string s.
The second line contains the string s itself, consisting of n lowercase Latin letters.
第一行包含一个整数 n(1≤n≤500000)—— 字符串 s 的长度。
第二行包含字符串 s 本身,由 n 个小写拉丁字母组成。
输出格式
Print one number — the maximum possible length of string journey on s.
输出一个数字——字符串 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}.
在第一个样例中,最长的字符串旅程是 {abcd, bc, c}。
在第二个样例中,一个合适的旅程是 {bb, b}。
输入解题思路,AI测评打分。不知道怎么写?