結果
問題 | No.460 裏表ちわーわ |
ユーザー | tktk_snsn |
提出日時 | 2020-12-14 16:06:45 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,738 bytes |
コンパイル時間 | 365 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 77,300 KB |
最終ジャッジ日時 | 2024-09-20 00:47:12 |
合計ジャッジ時間 | 10,637 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 110 ms
76,460 KB |
testcase_01 | AC | 72 ms
71,372 KB |
testcase_02 | AC | 148 ms
76,808 KB |
testcase_03 | AC | 36 ms
52,096 KB |
testcase_04 | AC | 36 ms
52,352 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 476 ms
76,624 KB |
testcase_09 | AC | 110 ms
76,312 KB |
testcase_10 | AC | 460 ms
76,828 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 431 ms
77,300 KB |
testcase_14 | AC | 468 ms
76,588 KB |
testcase_15 | AC | 456 ms
76,692 KB |
testcase_16 | WA | - |
testcase_17 | AC | 457 ms
76,820 KB |
testcase_18 | AC | 466 ms
76,572 KB |
testcase_19 | AC | 476 ms
76,576 KB |
testcase_20 | WA | - |
testcase_21 | AC | 443 ms
76,904 KB |
testcase_22 | AC | 458 ms
76,448 KB |
testcase_23 | AC | 445 ms
76,964 KB |
testcase_24 | AC | 469 ms
76,772 KB |
testcase_25 | AC | 84 ms
76,544 KB |
testcase_26 | AC | 69 ms
71,040 KB |
testcase_27 | AC | 71 ms
70,656 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)