結果
問題 | No.2731 Two Colors |
ユーザー | prd_xxx |
提出日時 | 2024-04-19 21:52:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 728 ms / 3,000 ms |
コード長 | 1,793 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 111,872 KB |
最終ジャッジ日時 | 2024-10-11 14:50:35 |
合計ジャッジ時間 | 11,976 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 718 ms
111,872 KB |
testcase_01 | AC | 718 ms
111,868 KB |
testcase_02 | AC | 728 ms
111,492 KB |
testcase_03 | AC | 121 ms
77,096 KB |
testcase_04 | AC | 154 ms
78,708 KB |
testcase_05 | AC | 150 ms
78,380 KB |
testcase_06 | AC | 187 ms
81,556 KB |
testcase_07 | AC | 184 ms
82,984 KB |
testcase_08 | AC | 139 ms
77,688 KB |
testcase_09 | AC | 302 ms
100,436 KB |
testcase_10 | AC | 132 ms
77,608 KB |
testcase_11 | AC | 409 ms
101,896 KB |
testcase_12 | AC | 295 ms
100,388 KB |
testcase_13 | AC | 377 ms
98,036 KB |
testcase_14 | AC | 212 ms
86,736 KB |
testcase_15 | AC | 149 ms
77,312 KB |
testcase_16 | AC | 237 ms
85,580 KB |
testcase_17 | AC | 260 ms
90,128 KB |
testcase_18 | AC | 162 ms
78,488 KB |
testcase_19 | AC | 255 ms
86,768 KB |
testcase_20 | AC | 231 ms
91,748 KB |
testcase_21 | AC | 177 ms
79,548 KB |
testcase_22 | AC | 354 ms
102,064 KB |
testcase_23 | AC | 194 ms
82,436 KB |
testcase_24 | AC | 161 ms
79,448 KB |
testcase_25 | AC | 114 ms
76,572 KB |
testcase_26 | AC | 286 ms
96,324 KB |
testcase_27 | AC | 325 ms
101,208 KB |
testcase_28 | AC | 288 ms
92,184 KB |
testcase_29 | AC | 180 ms
81,196 KB |
testcase_30 | AC | 217 ms
84,988 KB |
testcase_31 | AC | 197 ms
82,036 KB |
testcase_32 | AC | 432 ms
109,224 KB |
testcase_33 | AC | 39 ms
52,736 KB |
testcase_34 | AC | 38 ms
52,736 KB |
testcase_35 | AC | 38 ms
52,736 KB |
ソースコード
H,W = map(int,input().split()) A = [list(map(int,input().split())) for i in range(H)] dij = [(0,1),(1,0),(0,-1),(-1,0)] import heapq C = [[-1]*W for _ in range(H)] C[0][0] = 1 C[H-1][W-1] = 0 hq1 = [] hq0 = [] for di,dj in dij: ni = 0 + di nj = 0 + dj if 0 <= ni < H and 0 <= nj < W: heapq.heappush(hq1, (A[ni][nj],ni*W+nj)) for di,dj in dij: ni = H-1 + di nj = W-1 + dj if 0 <= ni < H and 0 <= nj < W: heapq.heappush(hq0, (A[ni][nj],ni*W+nj)) added0 = [[0]*W for _ in range(H)] added1 = [[0]*W for _ in range(H)] for k in range(H*W+1): if k%2==0: while hq1: a,v = heapq.heappop(hq1) i,j = divmod(v,W) if C[i][j] != -1: continue C[i][j] = 1 for di,dj in dij: ni = i + di nj = j + dj if 0 <= ni < H and 0 <= nj < W: if C[ni][nj] == 0: print(k+1) exit() if C[ni][nj] == -1 and added1[ni][nj] == 0: heapq.heappush(hq1, (A[ni][nj],ni*W+nj)) added1[ni][nj] = 1 break else: while hq0: a,v = heapq.heappop(hq0) i,j = divmod(v,W) if C[i][j] != -1: continue C[i][j] = 0 for di,dj in dij: ni = i + di nj = j + dj if 0 <= ni < H and 0 <= nj < W: if C[ni][nj] == 1: print(k+1) exit() if C[ni][nj] == -1 and added0[ni][nj] == 0: heapq.heappush(hq0, (A[ni][nj],ni*W+nj)) added0[ni][nj] = 1 break