#P1117. [NOI2016] 优秀的拆分
[NOI2016] 优秀的拆分
Description
If a string can be split into the form , where and are any non-empty strings, then we call this split of the string excellent. For example, for the string , if we set and , we have found one way to split this string into .
A string may have no excellent split, or it may have more than one excellent split. For example, if we set and , the above string can also be expressed as ; however, the string has no excellent split.
Now given a string of length , we need to count, over all substrings of and all their possible splits, the total number of excellent splits. Here a substring refers to a contiguous segment of the string.
Notes:
- Identical substrings that appear at different positions are considered different substrings, and their excellent splits are all counted in the answer.
- In a split, is allowed. For example, has the split .
- The string itself is also one of its substrings.
Input Format
Each input file contains multiple test cases.
The first line of the input file contains a single integer , indicating the number of test cases.
Then follow lines, each containing a string consisting only of lowercase English letters, as described above.
Output Format
Output lines. Each line contains an integer, indicating the total number of excellent splits among all splits of all substrings of .
4
aabbbb
cccccc
aabaabaabaa
bbaabaababaaba
3
5
4
7
Hint
Sample explanation.
We use to denote the substring of from the -th character to the -th character (1-based indexing).
In the first dataset, there are three substrings with excellent splits: , whose excellent split is , ; , whose excellent split is , ; , whose excellent split is , . The remaining substrings have no excellent splits, so the answer for the first dataset is .
In the second dataset, there are in total four substrings that have excellent splits, divided into two types: for the substrings , they share the same excellent split , , but since these substrings are at different positions, they are counted three times; for the substring , it has two excellent splits: , and , , which are different splits of the same substring and are both counted. Therefore, the answer for the second dataset is .
In the third dataset, and each have two excellent splits. Among them, is the example in the problem statement, so the answer is .
In the fourth dataset, , , , , and each have one excellent split, while has two excellent splits, so the answer is .
Constraints
For all test points, it is guaranteed that . The following limits apply to a single input within a dataset; that is, within the same test point, all of its datasets satisfy the constraints.
Let be the length of string . The detailed constraints for each test point are shown in the table below:
::cute-table{tuack}
| Test point ID | Special property | |
|---|---|---|
| All characters in are the same | ||
| ^ | ||
| None | ||
| ^ | ||
Translated by ChatGPT 5
京公网安备 11011102002149号