Official

B - Symmetric Painting Editorial by evima


When considering modulo \(N\), Alice’s move is to paint \(-x\) when the previously painted point is \(x\), and Bob’s move is to paint \(2K - x\) when the previously painted point is \(x\). If Alice starts by painting point \(0\), the points are painted in the order \(0, 2K, -2K, 4K, -4K, \ldots\). At the stage when all points every \(\mathrm{gcd}(N, 2K)\) steps apart have been painted, the state becomes “symmetric from both players’ perspectives” (where \(\mathrm{gcd}\) denotes the greatest common divisor). The same applies if Alice can start by painting point \(N/2\) and does so. Let’s call the process so far a “round.”

At this time, if the number of painted points is odd and the total number of points is even, Bob can paint the other point on his symmetry axis that hasn’t been painted yet to start the second round. (When the number of painted points is odd, it is impossible for both points on the symmetry axis to be painted.)

On the other hand, if the number of painted points is even, it would be Alice’s turn, but since an even number of points have been painted, both points on Alice’s symmetry axis are already painted. Therefore, the operation ends there, and it’s impossible to paint all points.

After finishing the second round, all pairs of symmetric points are either both painted or both unpainted, and in particular, the points on Alice’s and Bob’s symmetry axes are both painted, so no further operations can continue.

From the above, we can conclude that all points can be painted black only in the following cases:

  • \(\mathrm{gcd}(N, 2K) = 1\) (finished in one round)
  • \(\mathrm{gcd}(N, 2K) = 2\) and \(N/\mathrm{gcd}(N, 2K) (= N/2)\) is odd (finished in two rounds)

Sample implementation: https://atcoder.jp/contests/arc188/submissions/60033048

posted:
last update: