結果
問題 | No.460 裏表ちわーわ |
ユーザー | tktk_snsn |
提出日時 | 2020-12-14 16:08:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 509 ms / 2,000 ms |
コード長 | 1,748 bytes |
コンパイル時間 | 593 ms |
コンパイル使用メモリ | 81,540 KB |
実行使用メモリ | 76,396 KB |
最終ジャッジ日時 | 2023-10-20 05:05:23 |
合計ジャッジ時間 | 11,770 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 120 ms
76,040 KB |
testcase_01 | AC | 78 ms
72,588 KB |
testcase_02 | AC | 160 ms
76,184 KB |
testcase_03 | AC | 41 ms
53,336 KB |
testcase_04 | AC | 40 ms
53,336 KB |
testcase_05 | AC | 437 ms
76,148 KB |
testcase_06 | AC | 434 ms
76,148 KB |
testcase_07 | AC | 434 ms
76,148 KB |
testcase_08 | AC | 503 ms
76,140 KB |
testcase_09 | AC | 120 ms
76,044 KB |
testcase_10 | AC | 507 ms
76,140 KB |
testcase_11 | AC | 437 ms
76,148 KB |
testcase_12 | AC | 433 ms
76,152 KB |
testcase_13 | AC | 496 ms
76,396 KB |
testcase_14 | AC | 507 ms
76,140 KB |
testcase_15 | AC | 509 ms
76,132 KB |
testcase_16 | AC | 435 ms
76,156 KB |
testcase_17 | AC | 508 ms
76,136 KB |
testcase_18 | AC | 505 ms
76,136 KB |
testcase_19 | AC | 501 ms
76,140 KB |
testcase_20 | AC | 433 ms
76,148 KB |
testcase_21 | AC | 503 ms
76,132 KB |
testcase_22 | AC | 503 ms
76,140 KB |
testcase_23 | AC | 509 ms
76,136 KB |
testcase_24 | AC | 506 ms
76,140 KB |
testcase_25 | AC | 93 ms
75,940 KB |
testcase_26 | AC | 76 ms
70,428 KB |
testcase_27 | AC | 76 ms
70,488 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)