公式

D - Choose Your Role 解説 by evima 印刷ページ


Consider coloring the stones. Assume that pile $i$ has one stone of each of the $N - 1$ colors among colors $1, 2, \cdots, N$ excluding color $i$.
In the initial state, the following symmetry holds.

  • For $i \neq j$, whether pile $i$ has a stone of color $j$ is the same as whether pile $j$ has a stone of color $i$.

When the first player makes a move from a state where the symmetry holds, the symmetry no longer holds. As the second player, we aim to make moves so that the symmetry holds after each of our moves.

Suppose the first player removed stones of colors $c_1, c_2, \cdots, c_j$ from pile $i$. If the above symmetry was maintained before the first player's move, we can remove one stone of color $i$ from each of piles $c_1, c_2, \cdots, c_j$. Also, after this move, the symmetry holds again.

In the final state where no stones remain, the symmetry holds. Thus, by moving as described above, the second player can win.
We can simply implement this strategy. By managing the colors of the stones in each pile with a set or similar, it can be solved in, for example, $O(N^2 \log N)$.

Sample Implementation (C++)

投稿日時:
最終更新: