#P10215. [CTS2024] 字符串游戏
[CTS2024] 字符串游戏
Problem Description
Xiao P and Xiao B like playing games. They found skip. skip told them about the following game:
- There is a string consisting of lowercase letters. When the game starts, it is the string given by skip. The game scores points for Xiao P and Xiao B, and initially both of their scores are .
- Xiao P and Xiao B take turns operating on this string, with Xiao P moving first. On each turn, the current player can do the following:
- Choose a non-empty prefix of (it may be itself), gain points equal to the number of occurrences of this prefix in , and then delete this prefix from .
- If after some operation becomes empty, the game ends.
To help you better understand the rules, consider the following example:
- Initially, .
- Xiao P chooses the prefix of , gains 3 points, and becomes .
- Xiao B chooses the prefix of , gains 2 points, and becomes .
- Xiao P chooses , gains 1 point, the string becomes empty, and the game ends. Finally, Xiao P gets 4 points and Xiao B gets 2 points.
Xiao P wants to maximize (Xiao P's score minus Xiao B's score), while Xiao B wants to minimize this value. They want to know, assuming both players are perfectly smart, what the final value of (Xiao P's score minus Xiao B's score) will be.
Input Format
Read from standard input.
The input contains only one line: a string consisting of lowercase letters.
Output Format
Write to standard output.
Output one integer, representing the value of (Xiao P's score minus Xiao B's score) when the game ends, assuming both players are perfectly smart.
ababa
2
Hint
Sample 1 Explanation
The optimal strategies of Xiao P and Xiao B are the strategy given in the problem description.
Subtasks
Let be the length of the string . For all testdata, , and the string consists of lowercase letters.
| Subtask ID | Special Property | Points | |
|---|---|---|---|
| 1 | None | 10 | |
| 2 | Each character of is independently uniform in | ||
| 3 | Every character of is | 5 | |
| 4 | Every character of is or | 25 | |
| 5 | None | ||
| 6 |
Translated by ChatGPT 5