Another solution to 2241F

Revision en6, by WhiteCatBlackHat, 2026-08-30 07:44:27

I used AI to fix my grammar, so this blog might look like it was written by AI. You can read the Chinese version of this blog here.

Upd 2026.08.30: Replaced with a cleaner proof. Thanks to PhirainEX for the inspiration!

This is an alternative solution to 2241F - A Bit Odd, which differs from the editorial.

Obviously, if the remaining sequence length is $$$\le 1$$$, the number of inversions is $$$0$$$, making it a P-state (a losing state for the current player). Now, let's consider the following three states:

  • If the initial number of inversions is odd, Alice can simply remove the entire sequence, leaving an empty sequence. Thus, this is an N-state (a winning state for the current player), and Alice wins.
  • If the initial number of inversions is even, and there exists an index $$$i$$$ such that the number of inversions becomes odd after removing $$$s_i$$$ (which is equivalent to saying $$$s_i$$$ contributes an odd number of inversions), Alice can remove everything except $$$s_i$$$. This leaves a sequence of length $$$1$$$, so this is also an N-state, and Alice wins.
  • If neither of the above conditions is met, we can make an observation and guess that Bob wins (P-state).
Proof

Since we are dealing with a $$$01$$$-string, maintaining the number of inversions only requires prefix sums, so data structures like a Fenwick tree are unnecessary.

Implementation
Tags games, math, 2241f

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en6 English WhiteCatBlackHat 2026-08-30 07:44:27 2466 Replaced with a cleaner proof
en5 English WhiteCatBlackHat 2026-07-03 09:25:03 2
en4 English WhiteCatBlackHat 2026-07-03 09:18:52 0 (published)
en3 English WhiteCatBlackHat 2026-07-03 09:17:24 108
en2 English WhiteCatBlackHat 2026-07-03 09:09:19 39
en1 English WhiteCatBlackHat 2026-07-03 09:00:04 4837 Initial revision (saved to drafts)