結果
問題 | No.460 裏表ちわーわ |
ユーザー | tktk_snsn |
提出日時 | 2020-12-14 16:08:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 484 ms / 2,000 ms |
コード長 | 1,748 bytes |
コンパイル時間 | 370 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 76,832 KB |
最終ジャッジ日時 | 2024-09-20 00:47:46 |
合計ジャッジ時間 | 10,958 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 111 ms
76,720 KB |
testcase_01 | AC | 74 ms
72,064 KB |
testcase_02 | AC | 147 ms
76,760 KB |
testcase_03 | AC | 41 ms
52,096 KB |
testcase_04 | AC | 41 ms
52,352 KB |
testcase_05 | AC | 425 ms
76,828 KB |
testcase_06 | AC | 420 ms
76,564 KB |
testcase_07 | AC | 426 ms
76,824 KB |
testcase_08 | AC | 484 ms
76,520 KB |
testcase_09 | AC | 113 ms
76,728 KB |
testcase_10 | AC | 476 ms
76,832 KB |
testcase_11 | AC | 415 ms
76,536 KB |
testcase_12 | AC | 421 ms
76,600 KB |
testcase_13 | AC | 476 ms
76,756 KB |
testcase_14 | AC | 479 ms
76,500 KB |
testcase_15 | AC | 475 ms
76,572 KB |
testcase_16 | AC | 418 ms
76,520 KB |
testcase_17 | AC | 473 ms
76,568 KB |
testcase_18 | AC | 471 ms
76,568 KB |
testcase_19 | AC | 483 ms
76,824 KB |
testcase_20 | AC | 416 ms
76,448 KB |
testcase_21 | AC | 480 ms
76,572 KB |
testcase_22 | AC | 475 ms
76,404 KB |
testcase_23 | AC | 481 ms
76,784 KB |
testcase_24 | AC | 470 ms
76,576 KB |
testcase_25 | AC | 85 ms
76,544 KB |
testcase_26 | AC | 69 ms
70,528 KB |
testcase_27 | AC | 70 ms
71,296 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("Impossible") else: print(answer)