luogu#P10271. 漫长悄悄话
漫长悄悄话
Background
Which page does the story begin from?
Small stones, red earth, distant fire.
A groping outline, in the night sky, people who rush into the flames.
Hands clasping hands, hearts touching hearts.
Surging deep in the throat, my warm fire.
Problem Description
Some preliminary definitions:
-
the string formed by concatenating in order. That is, reverse .
-
the string that is the longest common prefix of the suffix starting at position and the suffix starting at position .
-
the string that is the longest common suffix of the prefix ending at position and the prefix ending at position .
-
the longest common prefix of and .
Given a string of length , compute:
$$\max\limits_{1 \le i < j \le n}\{\text{LCP}(\text{Rev}(\text{lcs}(i,j)),\text{lcp}(i,j))\}$$Input Format
The first line contains an integer .
The second line contains a string of length .
Output Format
Output a single number, which is the answer.
9
abbbabbba
3
Hint
Explanation of Sample 1
bba.
abb.
$\text{LCP}(\text{Rev}(\texttt{\color{blue}abb}),\texttt{\color{blue}bba}):$ bba.
It can be proven that there is no better choice than .
Constraints
For of the testdata, .
For of the testdata, .
For the other of the testdata, .
For of the testdata, , and the input consists only of integers and lowercase letters.
Translated by ChatGPT 5