DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord account linking.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

Yet Another Asymmetrical Game Problem

Back to problem

Editorial

Form a graph whose vertices are the empty cells and whose edges join adjacent empty cells. Include the cell containing the token.

If the initial graph contains any vertex of degree 000, coxld cannot win. If the token is already at an isolated vertex, coxld loses immediately. Otherwise, coxld cannot remove that isolated vertex on the first action, so codex can teleport there and win. Print −1-1−1 for such a board.

If there are no isolated vertices, print 111 and use the following strategy.

  • Move to any neighbour yyy of the current token vertex.
  • Turn every neighbour of yyy whose current degree is 111 into a wall. Compute these degrees before applying any wall creation in this action.
  • If codex's response is 0 0, the game is complete. Otherwise, yyy also becomes a wall; apply that change and repeat from the reported destination.

Let SSS be the set of neighbours removed by coxld. After codex moves, the remaining graph is G−{y}−SG-\{y\}-SG−{y}−S. The key is to ensure that this graph has no isolated vertices. If it is empty, codex has no destination and loses immediately. Otherwise, the same strategy is available regardless of codex's destination.

Compute every empty cell's degree initially. Whenever a cell becomes a wall, decrease the degrees of its surviving neighbours by 111. Each cell has at most four neighbours and is deleted at most once. Thus the total time for one board is O(RC)O(RC)O(RC), and the space usage is O(RC)O(RC)O(RC).

Proof

Suppose an isolated vertex www exists initially. If the token is at www, coxld has no legal move. Otherwise, coxld's destination must be adjacent to another vertex, so it cannot be www. Every cell coxld removes must be adjacent to that destination, so www is not removed either. codex can move to www, leaving coxld unable to move.

Now suppose has no isolated vertices. coxld moves to and removes all vertices whose only neighbour is . Let be this set and let .

Solution written by GPT6

GG
G
yyy
yyy
SSS
H=G−{y}−SH=G-\{y\}-SH=G−{y}−S

Suppose a surviving vertex www is isolated in HHH. Every neighbour of www in GGG must then belong to {y}∪S\{y\}\cup S{y}∪S. However, each vertex in SSS has only yyy as a neighbour, so none can be adjacent to w≠yw\ne yw=y. Therefore www had only yyy as a neighbour in GGG. It should consequently belong to SSS, contradicting that it survives in HHH. Thus HHH has no isolated vertices.

If HHH is empty, the actual board contains only the token vertex yyy, so codex loses. Otherwise, codex moves to a vertex of HHH and deletes yyy. Whatever destination codex chooses, the graph at the next coxld turn is HHH, which has no isolated vertices. Hence the proposed action preserves a forced win even against optimal responses.

The number of empty cells decreases after every round, and coxld always has a legal move on his turn. Eventually codex has no destination and loses.