A - mod M Game 2 解説 by evima
First, it’s important to focus on the moment when Alice plays her last remaining card, because:
- A player holding two or more cards can choose not to play a losing card, so they won’t lose immediately.
- If Alice does not lose when she plays her last card, she will win regardless of the result after Bob plays his last card.
- Therefore, whether Alice loses when she plays her last card determines the outcome of the game.
Let \(b\) be Bob’s last card in his hand. When Alice plays her last card, the sum of the numbers on the cards played is \(N(N+1) - b\). Therefore, we consider whether \(N(N + 1) - b\) can be congruent to \(0\) modulo \(M\).
(1) When \(N(N + 1) - b\) can be congruent to \(0\), i.e., when \(1 \leq (N(N+1) \bmod M) \leq N\)
Let \(c = N(N + 1) \bmod M\). If Bob can, in his previous \(N-1\) actions, play all cards except \(c\) so that \(b = c\), then Alice will lose when she plays her last card, leading to Bob’s victory. In fact, this is always possible. Specifically, Bob can act as follows:
- When Bob has 3 or more cards: Since he has at least 2 cards other than \(c\), he can keep \(c\) without losing.
- When Bob has 2 cards: Let \(a\) be Alice’s last card. When Bob plays his second-to-last card, the sum of the numbers on the cards played is \(N(N+1) - c - a = M - a \pmod{M}\), which is non-zero. Thus, Bob does not lose.
(2) When \(N(N + 1) - b\) cannot be congruent to \(0\)
In this case, no matter how Bob acts, Alice will not lose when she plays her last card. Thus, Alice wins in this case.
Therefore, the answer is: Bob wins if \(1 \leq N(N + 1) \bmod M \leq N\), and Alice wins otherwise. This can be determined in \(\mathrm{O}(1)\) time.
投稿日時:
最終更新: