GameOfTokens
2017 TCO Final · 2017-03-31 · by cgy4ever
Problem Statement
The rules of the game are as follows:
- The players take alternating turns. Alice plays first.
- When it is Alice's turn, she must choose one of the 'A' tokens and move it one cell to the left. Note that the destination cell must be empty.
- When it is Bob's turn, he must choose one of the 'B' tokens and move it one cell to the left. Note that the destination cell must be empty.
- The first player who is unable to make a valid move loses the game.
Among all boards that match pattern, let X be the number of boards for which Alice has a winning strategy. Compute and return the value X modulo (10^9 + 7).
Constraints
- pattern will contain between 1 and 50 characters, inclusive.
- Each character in pattern will be one of {'.', 'A', 'B', '?'}.
".AB" Returns: 0
Obviously, the only board that matches the given pattern is ".AB" itself. For this board there is only one way for the game to play out: Alice must move the only A token to the left. The board becomes "A.B". Bob must move the only B token to the left. The board becomes "AB.". Alice cannot make a valid move, so she loses the game. Thus, the board ".AB" is a losing position for Alice.
"???B" Returns: 1
Among all 27 boards that match pattern, the only board that is a winning position for Alice is ".AAB".
"???????...BBB" Returns: 0
"?.A?.B??.??B?" Returns: 517
"????????????????????" Returns: 612621096
Don't forget mod.
Submissions are judged against all 106 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GameOfTokens with a public method int count(string pattern) · 106 test cases · 2 s / 256 MB per case