公式

I - Exchange Game 解説 by en_translator


The state of the game can be represented by the current player and the owner of each card (Takahashi’s, Aoki’s, or on the table), for a total of \(2\times 3^{N+M+L}\) states.

By every move, the sum of the numbers written on the cards in Takahashi’s and Aoki’s hands decreases, so we never come back to the same state twice. Thus, the answer can be found by memorized recursion, where we check which player will always win from each state.

More specifically, from a state of the game, the player to make the next move will always win if and only if he can make a move such that, from the state after the move, the player to make the next move will always lose. This can be naturally expressed as a recursive function, which can be memorized.

function is_first_player_win(State of game, the player to make the next move): // returns True if the player to make the next player will always win
  for each possible move:
    if is_first_player_win(state after the move, opponent) is False:
      return True
  return False

For \(S=N+M+L\), there are \(O(3^S)\) states and \(O(S^2)\) transitions, so the problem has been solved in a total of \(O(3^S S^2)\) time.

More basic game problems:
ABC349E “Weighted Tic-Tac-Toe”
ABC354E “Remove Pairs”

投稿日時:
最終更新: