Palindrome Game Hard
This is Codeforces 1527B2, the hard version of Palindrome Game. Alice and Bob play a game on a binary string s of length n that contains at least one '0'.
Alice moves first, then the players alternate. On a turn a player may do exactly one of the following:
- Choose any
'0'and flip it to'1'. This move costs the player1dollar. - Reverse the whole string for free. This move is allowed only when the current string is not a palindrome and the previous move was not a reversal.
The game ends when every character is '1'. The player who spent fewer dollars wins, and if both spent the same amount the game is a draw.
Both players play optimally. Return "ALICE" if Alice wins, "BOB" if Bob wins, or "DRAW" if neither can force a win.
Examples
Input: "110"
Output: "ALICE"
Input: "0"
Output: "BOB"
Hints
Count the zeros and the number of mirrored pairs that differ. A pair `(i, n-1-i)` is mismatched when exactly one of its characters is `'0'`.
If the string is a palindrome, only the zero count matters: one zero or an even number of zeros favors Bob, otherwise Alice wins.
If the string is not a palindrome, Alice usually wins, except for the special draw when there are exactly two zeros forming exactly one mismatched pair.
Related Problems
Palindrome Game Hard
This is Codeforces 1527B2, the hard version of Palindrome Game. Alice and Bob play a game on a binary string `s` of length `n` that contains at least one `'0'`.