King Stone Bridge Game
Time limit1sMemory limit256 MB
Two kings alternate moving their own stones on N single-cell-row bridges, and the task is to name the winner under optimal play.
- Level
Medium7 of 10
- Topics
- Game theory, Math
- Solved
- No attempts yet
Problem
Whiteking and Blackking want to play a stone game on single-log bridges. The game uses bridges. The -th bridge is a row of cells. At the start, a white stone is placed on the first cell of every bridge, and a black stone is placed on the last cell of every bridge.
On each turn, a king must move one stone of their own color. A stone moves to another cell on the same bridge. It cannot jump over an opponent's stone, and it cannot stay on its current cell. As long as these rules hold, a stone may move in either direction, including away from the opposing stone. The kings take turns. A king who cannot move any stone on their turn loses.
If both kings play optimally, predict who wins.
Input
The first line contains , the number of bridges.
The second line contains , the number of cells on each bridge.
The third line contains the name of the king who moves first.
Output
Print the name of the winning king. The name always starts with a capital letter.
Constraints
Hint
Suppose a bridge has 6 cells, the white stone is on cell 3, and the black stone is on cell 5. The white stone can move to cell 1, 2, or 4. The black stone can move to cell 4 or 6. Note that a stone may move away from the opposing stone.