This is an interactive problem. A solution that only determines the winners can receive partial credit.
coxld and codex play a game on an board. Each cell is empty or a wall, and exactly one empty cell contains a token. The cell containing the token is also considered empty.
Two cells are adjacent if they share a side. Cells outside the board do not exist. The players alternate turns, starting with coxld, as follows.
A player who has no legal destination on their turn loses immediately. Thus coxld loses if there is no adjacent empty cell, while codex loses if the token's cell is the only empty cell.
You are given several boards. For each board, determine whether coxld can win when both players play optimally. If coxld cannot win, print -1 and proceed to the next board. Otherwise, print 1.
Your program first chooses one of the following modes. The same mode applies to every board.
In game mode, the judge plays codex. Before a game begins, the judge fixes an ordering of all cells. On each codex turn, it moves to the earliest legal destination in that ordering. The ordering is not revealed to you and never changes in response to your actions.
However, after each complete coxld action, your answer is rejected immediately if coxld can no longer win when both players play optimally from that state. A complete action includes moving the token and turning all chosen cells into walls. This check does not depend on the judge's actual next response. You must therefore keep a position from which coxld can win against every optimal response.
For example, consider three empty cells in a row, shown as P... coxld can move to the middle cell and turn both end cells into walls. codex then has no destination, so coxld wins. If coxld instead moves to the middle cell without creating any walls, codex could move to an end cell and turn the middle cell into a wall. coxld would have no next move. Therefore this action is rejected immediately in game mode.
First, read the number of test cases from the judge.
Then choose a mode and process the boards one at a time as described below. The judge does not send every board at the start.
Getting started: choosing a mode
After reading , print the number of your chosen mode on one line.
1: decision mode. Correctly determining the winners can earn of each subtask's points.2: game mode. Correctly determining the winners and playing every winning game can earn full credit.Choose a mode exactly once during the entire execution. It applies to every test case. Print the mode and flush the output buffer; the judge then sends the first board.
This dialogue uses game mode. The sample input contains the judge messages and the sample output contains the participant messages, each in chronological order. The entire input is not available at the start.
The first output 2 selects game mode. Skip the first board after printing -1. On the second board, print MOVE 1 2 1 and wall coordinates 1 1. The reply 0 0 ends that game.
On the third board, first move to (1,2) and turn (1,1) into a wall. The reply 1 3 means that codex moved the token to (1,3) and turned (1,2) into a wall. Then move to (1,4) and turn (1,3) into a wall. The reply 0 0 ends the game.
This example selects decision mode on the same three boards. The first output 1 selects the mode, and the subsequent -1, 1, and 1 classify the boards. Each decision is followed by the next board, with no game actions or game responses. All decisions are correct, earning 50% of the test-file score.
All coordinates are written as . The top-left cell is ; row numbers increase downward and column numbers increase to the right.
1. Decision mode
Input
For each test case, read the board's dimensions and initial state in the following format.
is a string of length describing row . A . denotes an empty cell, a # denotes a wall, and P denotes the empty cell containing the token. There is exactly one P.
Output
Print the result under optimal play by both players from the initial position on one line.
1 if coxld can win.-1 if coxld cannot win.Flush the output buffer, then read the next board. In this mode, you do not print any moves or wall coordinates, and the judge does not send game responses. After printing the decision for the last board, terminate your program.
2. Game mode
Input: the initial board
For each test case, read the board in the following format.
is a string of length describing row . A . denotes an empty cell, a # denotes a wall, and P denotes the empty cell containing the token. There is exactly one P.
Output: the initial decision
Print 1 if coxld can win when both players play optimally from the initial position, or -1 otherwise. Print the decision on one line and flush the output buffer.
After a correct -1, skip the game and immediately proceed to the next board. After a correct 1, play as coxld by repeating the following procedure.
Output: coxld's action
On each of your turns, print the following.
MOVE
The coordinates on the first line specify the token's destination, and is the number of cells to turn into walls. Print one pair of wall coordinates on each of the next lines. To create no walls, set and print only the first line.
All of the following conditions must hold.
You may turn the cell the token just left into a wall. The judge checks the coordinate bounds, adjacency, and whether the cells are empty.
After printing all lines of the action, flush the output buffer. After moving the token and creating all selected walls, the judge checks whether coxld can still win against optimal responses. Losing the ability to force a win is rejected immediately.
For example, on the board P.., you may print:
MOVE 1 2 21 11 3
This moves the token to and turns and into walls.
Input: the judge's response
If your action is valid, the judge sends two integers on one line.
0 0 means codex has no legal destination, so coxld has won. End the current game and read the next board. Do not print an additional 1 or any other end-of-game message.You may print MOVE at most times for one board. After the last board is complete, terminate your program.
Flushing and scoring
Always flush the output buffer after printing the mode, an initial decision, or a complete game action. For example, use cout.flush() or fflush(stdout) in C++, or print(..., flush=True) in Python.
An invalid format or initial decision, an illegal action, an action that loses the ability to force a win, too many actions, or unnecessary extra output is rejected. On an error, the judge terminates the entire interaction. If no more input is available, terminate your program.
The score multiplier for one test file is as follows.
A mistake in game mode does not earn the decision-mode multiplier. Each subtask's score is its point value multiplied by the minimum multiplier among all test files included in that subtask.
., \#, or P ().P.1 or 2 for the mode, and -1 or 1 for each initial decision.0 0 or coordinates with and .