結果
問題 | No.460 裏表ちわーわ |
ユーザー | tktk_snsn |
提出日時 | 2020-12-14 16:06:45 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,738 bytes |
コンパイル時間 | 877 ms |
コンパイル使用メモリ | 81,744 KB |
実行使用メモリ | 76,392 KB |
最終ジャッジ日時 | 2023-10-20 05:04:48 |
合計ジャッジ時間 | 12,283 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 119 ms
76,044 KB |
testcase_01 | AC | 77 ms
72,580 KB |
testcase_02 | AC | 158 ms
76,184 KB |
testcase_03 | AC | 41 ms
53,328 KB |
testcase_04 | AC | 40 ms
53,328 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 506 ms
76,136 KB |
testcase_09 | AC | 120 ms
76,044 KB |
testcase_10 | AC | 502 ms
76,140 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 489 ms
76,392 KB |
testcase_14 | AC | 502 ms
76,140 KB |
testcase_15 | AC | 506 ms
76,140 KB |
testcase_16 | WA | - |
testcase_17 | AC | 504 ms
76,140 KB |
testcase_18 | AC | 507 ms
76,136 KB |
testcase_19 | AC | 502 ms
76,132 KB |
testcase_20 | WA | - |
testcase_21 | AC | 504 ms
76,140 KB |
testcase_22 | AC | 505 ms
76,136 KB |
testcase_23 | AC | 506 ms
76,132 KB |
testcase_24 | AC | 504 ms
76,136 KB |
testcase_25 | AC | 91 ms
75,940 KB |
testcase_26 | AC | 73 ms
70,420 KB |
testcase_27 | AC | 76 ms
70,484 KB |
ソースコード
dxdy = ( (0, 0), (0, 1), (1, 0), (-1, 0), (0, -1), (1, 1), (-1, 1), (1, -1), (-1, -1), ) H, W = map(int, input().split()) G = list(list(map(int, input().split())) for _ in range(H)) A = [[0] * W for _ in range(H)] answer = 10 ** 10 L = H + W - 1 for bit in range(1 << L): #copy for i in range(H): for j in range(W): A[i][j] = G[i][j] #initial state res = [[0] * W for _ in range(H)] x = 0 for i in range(H): if (bit >> x) & 1: res[i][0] = 1 x += 1 for j in range(1, W): if (bit >> x) & 1: res[0][j] = 1 x += 1 for i in range(H): for dx, dy in dxdy: nx = i + dx ny = dy if 0 <= nx < H and 0 <= ny < W: A[nx][ny] ^= res[i][0] for j in range(1, W): for dx, dy in dxdy: nx = dx ny = j + dy if 0 <= nx < H and 0 <= ny < W: A[nx][ny] ^= res[0][j] #残りを構築 for i in range(1, H): for j in range(1, W): res[i][j] = A[i - 1][j - 1] for dx, dy in dxdy: nx = i + dx ny = j + dy if 0 <= nx < H and 0 <= ny < W: A[nx][ny] ^= res[i][j] #OKか確認 if sum(sum(a) for a in A) == 0: cnt = sum(sum(r) for r in res) if answer > cnt: answer = cnt # print(bit, bin(bit)[2:].zfill(L)) # print(*A, sep="\n") # print(sum(sum(r) for r in res)) # print(*res, sep="\n") # print("------------------------------------") if answer >= 10 ** 10: print(-1) else: print(answer)