#P16606. [SYSUCPC 2025] Palindrome
[SYSUCPC 2025] Palindrome
题目描述
Recently, Student A has been studying strings. Certain peculiar strings caught his attention, so he named such strings quasi-palindromic strings.
A string is a quasi-palindromic string if and only if the following two conditions are both satisfied:
-
There does not exist any contiguous substring of with length greater than or equal to 2 that is a palindromic string.
-
Suppose the length of is , there exist satisfying , such that after reversing the substring , becomes a palindromic string.
For example: The string aac is not a quasi-palindromic string because it contains the contiguous substring aa of length 2, which is a palindrome. The string abdc is not a quasi-palindromic string because there do not exist such that reversing the substring would turn into a palindrome. The string bcabca is a quasi-palindromic string.
Now, given a string , Student A wants to know how many contiguous substrings of are quasi-palindromic strings.
Here, contiguous substrings are distinguished solely by their starting and ending positions in the original string. For instance, in the string aba, the contiguous substring [1,1] (the first a) and the contiguous substring [3,3] (the last a) are considered two different contiguous substrings, even though they are both the character a.
输入格式
A string .
输出格式
An integer representing the number of contiguous substrings of that are quasi-palindromic strings.
abcabc
9
abc
3
提示
In the first sample, all contiguous substrings of length 1 are quasi-palindromic strings. Among substrings longer than 1, the quasi-palindromic strings are abcab, bcabc, and abcabc.