#P8631. [蓝桥杯 2015 国 AC] 切开字符串

    ID: 7690 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2015枚举前缀和Manacher 算法蓝桥杯国赛

[蓝桥杯 2015 国 AC] 切开字符串

Problem Description

Pear has a string, and he wants to cut it into two parts.

The string has length NN (105\le 10^5).

Pear wants to choose a position and cut the string into two non-overlapping parts without repetition or omission, with lengths tt and NtN-t (both parts must be non-empty).

Pear evaluates a cutting plan as follows:

Define an “odd palindrome substring” as a palindrome substring with odd length.

Suppose that in the two resulting substrings, the first part contains AA distinct odd palindrome substrings, and the second part contains BB distinct non-odd-palindrome substrings. Then the score of this plan is A×BA \times B.

Note that BB in the second part means “... non-odd-palindrome ...”, not “... odd-palindrome ...”.

Among all cutting plans, what is the maximum value of A×BA \times B?

Input Format

The first line contains a positive integer NN (105\le 10^5).

The next line contains a string of length NN, consisting only of lowercase English letters.

Output Format

Output one positive integer, representing the maximum value of A×BA \times B.

10
bbaaabcaba
38

Hint

For 20%20\% of the testdata, N100N \le 100.

For 40%40\% of the testdata, N1000N \le 1000.

For 100%100\% of the testdata, N105N \le 10^5.

Time limit: 1 second, 512 MB. Lanqiao Cup 2015, 6th National Contest.

Translated by ChatGPT 5