A12074 | String Journey
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted