Approach hintTry it first, then revealHide
Build a trie and compute for each node whether the player to move can force a win and whether they can force a loss. Combine the two flags at the root with the parity of k to decide the final game.
More in Game Theory
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | Stone Game III | LeetCode | Hard | Solve Stone Game III on LeetCode (opens in a new tab) | |||
| 2 | 1-2-K Game | Codeforces | Medium 1700 | Solve 1-2-K Game on Codeforces (opens in a new tab) | |||
| 3 | Stoned Game | Codeforces | Hard 1800 | Solve Stoned Game on Codeforces (opens in a new tab) | |||
| 4 | A Lot of Games | Codeforces | Hard 1900 | Solve A Lot of Games on Codeforces (opens in a new tab) | |||
| 5 | GameGame | Codeforces | Hard 1900 | Solve GameGame on Codeforces (opens in a new tab) | |||
| 6 | Tree Tag | Codeforces | Hard 1900 | Solve Tree Tag on Codeforces (opens in a new tab) | |||
| 7 | Cat and Mouse | LeetCode | Hard | Solve Cat and Mouse on LeetCode (opens in a new tab) | |||
| 8 | Not a Nim Problem | Codeforces | Hard 2100 | Solve Not a Nim Problem on Codeforces (opens in a new tab) | |||
| 9 | Lieges of Legendre | Codeforces | Hard 2200 | Solve Lieges of Legendre on Codeforces (opens in a new tab) |