結果
問題 | No.2731 Two Colors |
ユーザー | i_taku |
提出日時 | 2024-04-20 16:01:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,601 ms / 3,000 ms |
コード長 | 1,578 bytes |
コンパイル時間 | 427 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 120,232 KB |
最終ジャッジ日時 | 2024-10-12 11:44:31 |
合計ジャッジ時間 | 20,520 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,577 ms
120,056 KB |
testcase_01 | AC | 1,599 ms
120,048 KB |
testcase_02 | AC | 1,601 ms
120,232 KB |
testcase_03 | AC | 145 ms
77,636 KB |
testcase_04 | AC | 190 ms
79,584 KB |
testcase_05 | AC | 175 ms
78,728 KB |
testcase_06 | AC | 280 ms
83,292 KB |
testcase_07 | AC | 235 ms
83,640 KB |
testcase_08 | AC | 160 ms
78,816 KB |
testcase_09 | AC | 506 ms
105,108 KB |
testcase_10 | AC | 152 ms
78,224 KB |
testcase_11 | AC | 905 ms
111,764 KB |
testcase_12 | AC | 481 ms
104,120 KB |
testcase_13 | AC | 745 ms
105,624 KB |
testcase_14 | AC | 325 ms
89,140 KB |
testcase_15 | AC | 172 ms
78,064 KB |
testcase_16 | AC | 414 ms
89,832 KB |
testcase_17 | AC | 468 ms
94,328 KB |
testcase_18 | AC | 211 ms
79,864 KB |
testcase_19 | AC | 443 ms
90,772 KB |
testcase_20 | AC | 335 ms
93,924 KB |
testcase_21 | AC | 231 ms
80,520 KB |
testcase_22 | AC | 674 ms
108,460 KB |
testcase_23 | AC | 285 ms
85,016 KB |
testcase_24 | AC | 215 ms
81,472 KB |
testcase_25 | AC | 127 ms
77,476 KB |
testcase_26 | AC | 486 ms
100,096 KB |
testcase_27 | AC | 580 ms
107,408 KB |
testcase_28 | AC | 524 ms
98,148 KB |
testcase_29 | AC | 265 ms
82,848 KB |
testcase_30 | AC | 319 ms
87,600 KB |
testcase_31 | AC | 294 ms
84,356 KB |
testcase_32 | AC | 870 ms
118,452 KB |
testcase_33 | AC | 39 ms
53,024 KB |
testcase_34 | AC | 39 ms
54,352 KB |
testcase_35 | AC | 41 ms
53,476 KB |
ソースコード
from heapq import heappop, heappush H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] di, dj = [1, 0, -1, 0], [0, 1, 0, -1] hq1 = [] hq2 = [] C = [[-1] * W for _ in range(H)] C[0][0] = 0 C[-1][-1] = 1 add1 = [[False] * W for _ in range(H)] add2 = [[False] * W for _ in range(H)] for d in range(4): ni, nj = di[d], dj[d] if 0 <= ni < H and 0 <= nj < W: add1[ni][nj] = True heappush(hq1, (A[ni][nj], ni, nj)) for d in range(4): ni, nj = H - 1 + di[d], W - 1 + dj[d] if 0 <= ni < H and 0 <= nj < W: add2[ni][nj] = True heappush(hq2, (A[ni][nj], ni, nj)) ans = 1 while hq1 and hq2: if ans & 1: v, i, j = heappop(hq1) C[i][j] = 0 for d in range(4): ni, nj = i + di[d], j + dj[d] if 0 <= ni < H and 0 <= nj < W and C[ni][nj] != -1 and C[ni][nj] != C[i][j]: print(ans) exit() if 0 <= ni < H and 0 <= nj < W and C[ni][nj] == -1 and not add1[ni][nj]: add1[ni][nj] = True heappush(hq1, (A[ni][nj], ni, nj)) else: v, i, j = heappop(hq2) C[i][j] = 1 for d in range(4): ni, nj = i + di[d], j + dj[d] if 0 <= ni < H and 0 <= nj < W and C[ni][nj] != -1 and C[ni][nj] != C[i][j]: print(ans) exit() if 0 <= ni < H and 0 <= nj < W and C[ni][nj] == -1 and not add2[ni][nj]: add2[ni][nj] = True heappush(hq2, (A[ni][nj], ni, nj)) ans += 1 assert 0