Approach
Breadth-first search
For ARC031 B — 埋め立て, the implementation explores reachable states in layers, which is the standard shape for unweighted shortest paths and minimum-step transitions.
- Model each valid configuration as a state and each legal move as an edge.
- Seed the queue with the starting state and mark it immediately.
- Expand each state once, recording distance or reachability for unseen neighbours.
Code notes
- 58 lines of Python from the credited upstream file arc031_2.py.
- The implementation visibly relies on sequence storage, work queue.
- No explicit loop blocks detected.
Complexity
Verify that each state and transition is processed only a bounded number of times; that determines the traversal cost.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12 3 4def main():5 from collections import deque6 7 n = 108 s = [list(input()) for _ in range(n)]9 10 land_count = 011 dxy = [(0, 1), (0, -1), (-1, 0), (1, 0)]12 13 for i in range(n):14 for j in range(n):15 if s[i][j] == "o":16 land_count += 117 18 for i in range(n):19 for j in range(n):20 d = deque()21 d.append((j, i))22 visited = [[False for _ in range(n)] for _ in range(n)]23 visited[i][j] = True24 count = 025 26 while d:27 dix, diy = d.popleft()28 29 for dx, dy in dxy:30 nx = dix + dx31 ny = diy + dy32 33 if nx < 0 or nx > 9:34 continue35 36 if ny < 0 or ny > 9:37 continue38 39 if s[ny][nx] == "x":40 continue41 42 if visited[ny][nx]:43 continue44 45 visited[ny][nx] = True46 d.append((nx, ny))47 count += 148 49 if count == land_count:50 print("YES")51 exit()52 53 print("NO")54 55 56if __name__ == "__main__":57 main()58