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,…,tkt_1, \dots, t_k 为长度为 kk 的旅程(journey),当且仅当对每个 i>1i > 1,tit_i 是 ti−1t_{i-1} 的子串,且 tit_i 的长度严格小于 ti−1t_{i-1} 的长度。例如,{ab, b}\{ab,\, b\} 是一个旅程,但 {ab, c}\{ab,\, c\} 和 {a, a}\{a,\, a\} 不是。

定义字符串 ss 上的一个旅程为一个旅程 t1,…,tkt_1, \dots, t_k,使得其所有组成部分均可嵌套于 ss 中:即存在一个字符串序列 u1,…,uk+1u_1, \dots, u_{k+1}(其中每个 uiu_i 可为空),满足

s=u1 t1 u2 t2 … uk tk uk+1.s = u_1\, t_1\, u_2\, t_2\, \dots\, u_k\, t_k\, u_{k+1}.

例如,{ab, b}\{ab,\, b\} 是字符串 abbabb 上的一个旅程,但不是字符串 babbab 上的旅程,因为旅程中的字符串 tit_i 必须从左到右依次出现。

一个字符串上旅程的长度即为其所含字符串的个数。请确定给定字符串 ss 上可能的旅程的最大长度。

输入格式

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.

第一行包含一个整数 nn(1≤n≤500 0001 \leq n \leq 500\,000)—— 字符串 ss 的长度。

第二行包含字符串 ss 本身,由 nn 个小写拉丁字母组成。

输出格式

Print one number — the maximum possible length of string journey on s.

输出一个数字——字符串 ss 上字符串旅程的最大可能长度。

输入输出样例

  • 输入#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测评打分。不知道怎么写?

首页