Editorial for CTU Open Contest 2018 - Split Game


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
  • Each impartial game is equivalent to NIM.
  • Sum of games has nimber equivalent to XOR of nimbers of individual games.
  • Note that adding two same piles does not change the outcome.
  • We precompute nimbers up to piles of size 2000 (DP).
  • XOR nimbers of games on the input.
  • If XOR is zero second player wins, otherwise first player wins.

Complexity \mathcal O(N^2 \log N)

If you try hard, you can achieve \mathcal O(N^2)


Comments

There are no comments at the moment.