QOJ.ac

QOJ

时间限制: 4 s 内存限制: 512 MB 总分: 100

#13236. Black-Red Rabbit

统计

Last month, PinkRabbit reached LGM on the competitive programming website Codeforces.

PinkRabbit has now encountered a simple problem, but he is busy browsing Zhihu to take the top spot on the Codeforces world leaderboard, so he has handed the problem over to you:

Given a string $s$ of length $n$ consisting only of lowercase English letters, you need to find the maximum $k$ such that there exist:

$1 \le l_1 \le r_1 < l_2 \le r_2 < l_3 \le r_3 < \dots < l_k \le r_k \le n$

(i.e., the left and right endpoints of the $k$ intervals are strictly increasing and the intervals are pairwise disjoint)

such that for every $1 \le i < k$, $s[l_{i+1} \dots r_{i+1}]$ is a strict substring of $s[l_i \dots r_i]$.

Here, $s[l \dots r]$ denotes the substring of $s$ consisting of the characters from the $l$-th to the $r$-th position.

String $A$ is a strict substring of string $B$ if and only if $A$ can be obtained by deleting some characters from the beginning and the end of $B$ (the number of characters deleted from the beginning and the end can be zero, but the total number of deleted characters must be greater than $0$).

Input

A single string $s$.

Output

A single integer representing the answer.

Examples

Input 1

bbcb

Output 1

2

Note 1

$l_1 = 1, r_1 = 2, l_2 = 4, r_2 = 4$

Input 2

abcdbcc

Output 2

3

Note 2

$l_1 = 1, r_1 = 4, l_2 = 5, r_2 = 6, l_3 = 7, r_3 = 7$

Input 3

pinkrabbitpinkrtxdytxinkrdynkrabnknealchentxdy

Output 3

6

Constraints

  • Subtask 1 (10 points): $n \le 100$
  • Subtask 2 (15 points): $n \le 1000$
  • Subtask 3 (25 points): $n \le 3 \times 10^4$
  • Subtask 4 (30 points): $n \le 10^5$
  • Subtask 5 (20 points): No special constraints.

For all data, $1 \le n \le 5 \times 10^5$, and the string contains only lowercase English letters.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.