Paweł i Gaweł
Time limit3sMemory limit128 MB
Two players alternate moving a pawn across a grid, swapping floors whenever it enters a marked cell, each trying to hold the upper floor at the end.
- Level
Medium6 of 10
- Topics
- Game theory, Dynamic programming, Matrix
- Solved
- No attempts yet
Problem
Paweł and Gaweł share one house: Paweł lives on the upper floor and Gaweł on the lower floor. When they first moved in, both wanted the upper floor, so they settled the dispute with a game.
The game is played on a board of N rows and M columns, divided into unit cells. A pawn starts on the corner cell at coordinates . The two players move in turn; on each move the pawn is pushed one cell forward, either to the next column or to the next row. This repeats until the pawn reaches the cell at coordinates . Moving off the board is not allowed.
K of the cells are marked with a cross. Every time the pawn enters a marked cell, Paweł and Gaweł swap floors.
Paweł moves first, and at the start Paweł occupies the upper floor. The corner cell is never marked. Assuming both players play optimally (each trying to end up on the upper floor), determine who lives on the upper floor when the pawn reaches .
Here the coordinate denotes row , column . In other words, the lower-left corner, row 1 column 1, is the starting cell.
Input
The first line contains a natural number Z (), the number of test sets. The sets follow in order.
The first line of each set contains three space-separated natural numbers N, M, and K (; ), as described above.
Each of the next K lines contains the coordinates of one marked cell as two space-separated natural numbers and (, ), the row and column of that cell.
Cell is never marked, and all marked cells are distinct.
Output
For each test set, print one line: Pawel if Paweł can secure the upper floor no matter how his opponent moves, or Gawel if Gaweł can secure the upper floor no matter how his opponent moves.