Problem E
Jumex-train
Languages
en
sv
After a long day of problem-solving, Sictor Miölc and the
rest of the Swedish delegation at BOI 2024 (Bossy Olympiad in
International Relations) have returned to the hotel with 5
medals and an honorable mention. However, they soon realize
that the store has closed, and they only have one can of Jumex
left! The participants decide to play a game for the last can
of Jumex, and what could be better than a modified version of
Mexican Train?
This is how the game works:
$N$ players sit around a
table and first distribute $S$ domino tiles randomly to everyone
at the table. Each domino tile can be represented as a unique
set of two integers between $0$ and $M$, meaning that if a tile consists
of the numbers $(x, y)$,
then $(y, x)$ cannot also
exist. In total, there are $\frac{M(M+1)}{2}$ different domino
tiles.
At the start, the tile $(M,
M)$ is placed in the middle of the table, and each
participant receives their $S$ randomly assigned domino tiles.
The remaining tiles are placed in a pile to the side. Since
Sictor performed the best among the BOI participants, he gets
to start. Each player has a private track that only they can
use at first. Additionally, there is a single shared side track
that can be created.
A typical move works as follows: the participant selects a
domino tile that has on one side a matching value to that of
some track they are allowed to build on. For example, in the
beginning, they must place a tile that has the set $(M, x)$ where $x$ is any integer. The moves function
such that if a tile $(x,
y)$ is placed on a track because there was previously an
$x$ there, then the
required value for placing a new tile on that track updates to
$y$. In other words, the
track must now be continued with a tile $(y, z)$.
On the side track, anyone can place a tile with the requirement
that the first tile must be of the form $(M, x)$ where $x$ is any value.
If a player cannot place a domino tile during their turn, they
must draw a domino tile from the pile of unused tiles that was
formed at the beginning of the game (if no tiles remain in the
pile, they do not need to draw one). The player’s track also
becomes open for others to use until that player places a tile
on it again.
If a player places a tile of the form $(x, x)$, the next player in turn must
place a tile on the same track of the form $(x, y)$ where $y$ is some integer. If they cannot do
so, the same rule applies as when they cannot place a tile
(draw a tile, their track becomes open), and the next player
must then place a tile $(x,
y)$ on that track. In other words, this rule continues
to apply to the following players until someone places a tile
$(x, y)$ on that
track.
If no one around the table can make a valid move or if someone
gets rid of all their tiles, the game ends, and the player with
the lowest sum of remaining tiles wins.
Since Sictor Miölc did so well at BOI, he not only gets to
start but also gets to declare after each move if he wants to
swap a tile with another player. He then selects one of his
tiles and a player, and that player must then exchange that
tile with one of their own.
Sictor also happens to be the only one who has played before,
and since everyone else is confused by the rules, they play
completely randomly. It is your job to write a program that
ensures Sictor Miölc wins the game and thereby a can of
Jumex.
Input
First, the three integers $N,
M, S$ appear on a line.
Then follows the game sequence until it ends:
A line with the integer $Q$, the number of legal moves you can
make
This is followed by $Q$
lines where each line consists of three integers $s_i, x_i, y_i$, indicating that you
can place the domino $(x_i,
y_i)$ on track $s_i$.
Next, a line with the integer $D$, the number of domino tiles you
currently have.
Then $D$ lines follow with
the integers $a_i, b_i$,
indicating that you have the domino tile $(a_i, b_i)$ in hand.
After this, $N-1$ lines
follow with three integers $s_i,
x_i, y_i$ indicating that player $i$ has made the move of placing the
tile $(x_i, y_i)$ on track
$s_i$. If the player
cannot place a tile, instead $-1$ is sent, and if the game is over,
$-2$ is sent.
Output
After each time your domino tiles have been printed, you
must output both the move you want to make (in the form
$s_i$ $x_i$ $y_i$), as well as whether you want to
swap a tile with someone else.
If so, write on the next line "SWAP", followed by the player
you want to swap with and the tile you want to swap, i.e., 3
integers.
If you do not want to swap, write "NO-SWAP" instead.
Make sure to flush the output after each
move, otherwise, you may receive Time
Limit Exceeded. In C++, this can be done with cout << flush or fflush(stdout); in Python with stdout.flush(); and in Java with System.out.flush().
Scoring
Your solution will be tested on a set of test case groups. Points for a given test case are calculated according to the following formula:
\[ Score = min(100, 100\cdot (1-(\frac{log(1000\cdot percentile + 1)}{log(1001)})^{0.8})) \]where "percentile" is the percentile of all players you
belong to score-wise at the end of a game.
The score you receive per group is the average score of all
test cases in the group.
Group |
Points |
Constraints |
$1$ |
$50$ |
$M = 9, S = 6$ |
$2$ |
$50$ |
No additional constraints |
Read | Sample Interaction 1 | Write |
---|
3 4 3 2 0 1 4 3 1 4 3 3 3 1 4 2 2
0 1 4 SWAP 1 3 3
1 2 4 3 3 4 1 0 1 2 2 2 2 1 2
0 1 2 NO-SWAP
3 3 3 -1 0 1 2 2 0 0
-1
-1 -1 -2