#P10915. [蓝桥杯 2024 国 B] 最长回文前后缀

    ID: 12371 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>二分2024哈希 hashingKMP 算法蓝桥杯国赛

[蓝桥杯 2024 国 B] 最长回文前后缀

Problem Description

Xiaoming especially likes palindromic strings, but palindromic strings are rare. So he defines two non-overlapping prefix and suffix of the same length of a string as a “palindromic prefix-suffix” if and only if concatenating this prefix and suffix forms a palindrome. Then, for a string S=c1c2c3,,cnS=c_1c_2c_3,\cdots,c_n, the length L(S)L(S) of the “longest palindromic prefix-suffix” is

arg maxxS[1,x]=(S[nx+1,n])T\argmax\limits_{x}{S_{[1,x]} = (S_{[n-x+1,n]})^T}

where S[i,j]S_{[i,j]} denotes a substring cici+1cjc_ic_{i+1}\cdots c_j of SS, and STS^T denotes the string obtained by reversing SS.

For a given string SS, Xiaoming wants to modify it so that L(S)L(S^\prime) is as large as possible. The modification allows deleting any substring of arbitrary length from the string. For example, after deleting the substring S[3,5]S_{[3,5]} from S=abcdebijbbaS = \texttt{abcdebijbba}, SS becomes abbijbba\texttt{abbijbba}.

Xiaoming wants to know: after the modification, what is the maximum possible value of L(S)L(S^\prime) for the new string SS^\prime?

Input Format

The input consists of 11 line, a string SS.

Output Format

The output consists of 11 line, an integer representing the answer.

abcdebijbba
3

Hint

Sample Explanation

In the approach described in the statement, after deleting S[3,5]S_{[3,5]}, S=abbijbbaS^\prime = \texttt{abbijbba}, and L(S)=3L(S^\prime) = 3.

Constraints

For 20%20\% of the testdata, S500|S| \le 500.
For 100%100\% of the testdata, S500000|S| \le 500000, and SS contains only lowercase letters.

Translated by ChatGPT 5