Endgame
Time limit1sMemory limit1024 MB
Given n valid moves on an n by n board, decide whether Alice captures Bob in one turn, forces a tie by teleporting to a cell Bob cannot reach, or loses.
- Level
Hard8 of 10
- Topics
- Math, Hash map, Implementation
- Solved
- No attempts yet
Problem
Chaos is a variant of chess played by two players taking turns on an board. All pieces share the same set of valid moves, which are agreed on before the game starts.
In a single turn, a player picks exactly one of their pieces and does one of the following:
- Makes up to two valid moves with the chosen piece. Any piece the chosen piece lands on during these moves is captured.
- Teleports the chosen piece to any cell on the board that is not occupied by another piece.
- Leaves the chosen piece where it is.
Alice and Bob are in the endgame of a match. Each has a single piece left, and there are only two turns left, with Alice moving first.
Alice can only win by capturing Bob's piece on her turn. If she cannot, she can force a tie by teleporting her piece to a cell that Bob cannot capture on his turn. If neither is possible, Bob wins by capturing Alice's piece no matter what she does. Determine Alice's best outcome.
Input
The first line contains an integer (), the size of the board and the number of valid moves.
The second line contains two integers and (), the column and row of Alice's piece.
The third line contains two integers and (), the column and row of Bob's piece.
Each of the next lines contains two integers and (). This is a valid move that shifts a piece columns to the right and rows up, provided the piece stays on the board. All valid moves are distinct.
Columns are numbered 1 to from left to right, and rows are numbered 1 to from bottom to top.
Output
If Alice can capture Bob's piece on her turn, print Alice wins.
If Alice can force a tie by teleporting her piece to a cell that Bob cannot capture on his turn, print tie followed by the two coordinates and of any such cell. If several cells work, any one is accepted.
Otherwise, if Bob can capture Alice's piece no matter what she does, print Bob wins.