Yet Another Contest 8 P4 - Fluke 2

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 5.0s
Memory limit: 256M

Author:
Problem types

Now that Nils has proven that his moments of strategic brilliance are not flukes, Josh has been challenged to do the same. To do so, they will play the following game.

The game will be played on an N by M grid of initially white cells. The rows are numbered from 1 to N, while the columns are numbered from 1 to M. Denote the cell in the r-th row and the c-th column as cell (r, c).

Nils and Josh will take alternating turns. In each turn, the player must select a cell, and then toggle its colour between black and white. Furthermore, this cell cannot be the same as the cell last chosen by the other player. The player who goes first will win if there are three consecutive black cells (adjacent cells in the same row or column; diagonals do not count) at any point during the first 400 total turns (that is, each player has had 200 turns each). Otherwise, the player who goes second will win.

In order to prove that his victories are a result of his strategic brilliance rather than just flukes, Josh must win T consecutive games. To make things a little fairer, Josh will be allowed to decide which player takes the first turn. Can you help Josh win all T games?

It can be proven that if it is possible for the first player to win within the first 400 total turns, there is a strategy which allows them to win within the first 15 total turns. Thus, if Josh chooses to go first, he must win within 15 total turns for full points.

Constraints

1 \le N \le 100

\max(2, N) \le M \le 100

1 \le T \le 16

Subtask 1 [30%]

N = 1

Subtask 2 [70%]

No additional constraints.

Scoring

Let Z be the number of turns in any particular game.

If you choose for Josh to go second, then you will receive 100\% of the points if Josh wins, and 0\% otherwise.

If you choose for Josh to go first, then you will receive P\% of the points of the points if Josh wins, and 0\% otherwise, where P is determined by the following table:

ZP
1 \le Z \le 30100 - 2 \times \max(0, Z - 15)
30 < Z \le 20060
200 < Z \le 40040
Z > 4000

The score for a testcase is the minimum score amongst any of its games. The score for a subtask is the minimum score amongst any testcase in the subtask.

Interaction

This is an interactive problem, where the interactor will play the role of Nils. Since the moves that the interactor can make depends on your moves, the interactor will be adaptive.

At first, you should read in three space-separated integers on a single line, denoting the values of N, M and T respectively. Note that the values of N and M are the same for all T games.

Each of the following T interactions represents a single game.

At the beginning of each game, on a single line, you should output either 1 or 2. Outputting 1 indicates that Josh will take the first turn, whilst outputting 2 indicates that Nils will take the first turn. If you do not do so, the interactor will output I on a single line, and you will be responsible for terminating your program to receive a Wrong Answer verdict; otherwise, your program will receive an arbitrary verdict.

Then, the game will begin. When it is Josh's turn, on a single line, output your selected cell in the format r c, representing that Josh will toggle the cell (r, c). You should then read in a character on a new line, which will be one of W, L, C, or I. These denote that Josh has won, Josh has lost, the game should continue, or an invalid turn has occurred (such as an invalid output format or the same cell being toggled twice in a row) respectively. Upon reading L or I, you should terminate your program to receive a Wrong Answer verdict; otherwise, your program will receive an arbitrary verdict. Upon reading W, if you have not yet played all T games, then you should begin the next interaction for the following game. Upon reading C, you should continue the current game.

When it is Nils's turn, you should read in a line of input in the format r c, representing that Nils will toggle the cell (r, c). Then, you should read in a character on a new line, which will be one of W, L, or C. These have the same meaning as above, so you should terminate your program upon reading L, begin the next game upon reading W, and continue the current game upon reading C.

If you manage to win all T games, then you will receive an Accepted verdict for that test case.

Please note that you may need to flush stdout after each operation, or interaction may halt. In C++, this can be done with fflush(stdout) or cout << flush (depending on whether you use printf or cout). In Java, this can be done with System.out.flush(). In Python, you can use sys.stdout.flush().

Sample Interaction 1

>>> denotes your output. Do not print this out.

1 4 1
>>> 1
>>> 1 1
C
1 4
C
>>> 1 2
C
1 1
C
>>> 1 3
W

Explanation for Sample Interaction 1

Here, the game is played on a 1 by 4 grid, and Josh only has to win a single game. Josh chooses to go first.

Josh begins by toggling the cell (1, 1) to black, and Nils follows by toggling the cell (1, 4) to black. Josh then toggles the cell (1, 2) to black, and Nils responds by toggling the cell (1, 1) back to white. Josh then wins by toggling the cell (1, 3) to black.

Sample Interaction 2

1 2 1
>>> 2
1 1
C
>>> 1 2
C
1 1
C
>>> 1 2
...
1 1
C
>>> 1 2
W

Explanation for Sample Interaction 2

Here, the game is played on a 1 by 2 grid, and Josh only has to win a single game. Josh chooses to go second.

Note that once Nils makes the first move of toggling the cell (1, 1) to black, Josh can only ever toggle the cell (1, 2), and Nils can only ever toggle the cell (1, 1). Note that ... does not actually appear in the output, and represents repeating turns that have been omitted for concision. Once both player have had 200 turns each, 400 total turns have elapsed, and Josh wins.


Comments

There are no comments at the moment.