Created
December 27, 2025 05:13
-
-
Save maehrm/bf298382a9c6ca9ddd720f9b4aaee300 to your computer and use it in GitHub Desktop.
D - Domino Covering XOR https://atcoder.jp/contests/abc407/tasks/abc407_d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| sys.setrecursionlimit(10**9) | |
| def dfs(i): | |
| global ans, domino | |
| if i == H * W: | |
| score = 0 | |
| for y in range(H): | |
| for x in range(W): | |
| if not domino[y * W + x]: | |
| score ^= A[y][x] | |
| ans = max(ans, score) | |
| return | |
| # ドミノを置かない | |
| dfs(i + 1) | |
| y, x = divmod(i, W) | |
| # ドミノを横に置く | |
| if x + 1 < W and not domino[y * W + x] and not domino[y * W + (x + 1)]: | |
| domino[y * W + x] = domino[y * W + (x + 1)] = True | |
| dfs(i + 1) | |
| domino[y * W + x] = domino[y * W + (x + 1)] = False | |
| # ドミノを縦に置く | |
| if y + 1 < H and not domino[y * W + x] and not domino[(y + 1) * W + x]: | |
| domino[y * W + x] = domino[(y + 1) * W + x] = True | |
| dfs(i + 1) | |
| domino[y * W + x] = domino[(y + 1) * W + x] = False | |
| return | |
| H, W = map(int, input().split()) | |
| A = [list(map(int, input().split())) for _ in range(H)] | |
| domino = [False] * (H * W) | |
| ans = 0 | |
| dfs(0) | |
| print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment