#P11133. Interactive Stone Piles Game
Interactive Stone Piles Game
Interactive Stone Piles Game
Hikari and Tairitsu have invented a new game using shards of glass. There are ( n ) piles of shards numbered from ( 0 ) to ( n-1 ). You are given a sequence ( a = [a_0, a_1, \ldots, a_{n-1}] ) where each ( a_i ) is a positive integer representing the number of shards in pile ( i ).
The two players take turns performing the following operation:
- Choose a nonempty pile ( i ) and remove at least one shard from it (you may remove all shards).
- Then, distribute the remaining shards in pile ( i ) arbitrarily among all nonempty piles (the shards may also be returned to the same pile).
Hikari moves first, and the player who cannot make a move loses.
This is an interactive problem. You will play the game as either Hikari or Tairitsu against an interactive judge. Based on the initial configuration ( a_0, a_1, \ldots, a_{n-1} ), you need to decide whether to go first (Hikari) or second (Tairitsu), and then interact with the judge according to the protocol described below.
Interactive Protocol:
This problem uses multiple test cases aggregated together. For each test case, the interaction will be as follows:
-
The judge calls the function
Init(int n, int op, vector<int> a)
once. Here,n
is the number of piles,op
is a subtask identifier, anda
is the initial sequence of shard counts (with indices (0) through (n-1)). Your function should return either 0 (to play first as Hikari) or 1 (to play second as Tairitsu). -
If you choose to move first (i.e. you return 0), the judge will call
Play()
to obtain your move. Otherwise, this call is skipped. -
The judge will then modify the sequence
a
according to its move and callGet(vector<int> a)
to deliver the new state to your program. -
After that, the judge alternates between calling
Play()
andGet(vector<int> a)
so that in every pair of consecutive calls, one isPlay()
and the other isGet()
. -
In particular, if after a call to
Play()
the judge transforms the sequence into a terminal state or cannot move, the judge will decide the outcome and terminate the test case without any further calls.
Important:
- This is an interactive problem. Do not include a
main
function in your submission. - Only submissions in C++ are officially supported, and C++14 (GCC 9) is not allowed.
Good luck, and may the best strategist win!
inputFormat
The input for each test case is given via interaction with the judge. Initially, the judge provides an integer ( n ) (the number of piles), an integer ( op ) (the subtask identifier), and a vector ( a ) of length ( n ) representing the initial number of shards in each pile. The interaction functions Init
, Get
, and Play
are then called by the judge according to the protocol described above.
outputFormat
Your output is generated through the functions Init
, Get
, and Play
. In particular, Init
should return 0 (if you choose to be Hikari) or 1 (if you choose to be Tairitsu), and Play
should return a valid move as an updated vector ( a ) after your turn.
sample
Test Case 1:
n = 3
a = [5, 1, 2]
(Interactive sequence simulated: your first move is required, followed by judge's move, etc.)
Your solution returns 0 in Init and then always makes a move by removing all stones from the first nonempty pile. For example, if the current state is [5,1,2], after your move it becomes [0,1,2].