結果
問題 | No.2731 Two Colors |
ユーザー |
![]() |
提出日時 | 2024-04-19 22:16:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,538 ms / 3,000 ms |
コード長 | 1,372 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 82,128 KB |
実行使用メモリ | 119,988 KB |
最終ジャッジ日時 | 2024-04-19 22:17:13 |
合計ジャッジ時間 | 18,211 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,512 ms
119,176 KB |
testcase_01 | AC | 1,538 ms
119,988 KB |
testcase_02 | AC | 1,507 ms
119,452 KB |
testcase_03 | AC | 115 ms
76,800 KB |
testcase_04 | AC | 145 ms
78,976 KB |
testcase_05 | AC | 157 ms
78,336 KB |
testcase_06 | AC | 245 ms
83,616 KB |
testcase_07 | AC | 210 ms
83,396 KB |
testcase_08 | AC | 133 ms
78,024 KB |
testcase_09 | AC | 457 ms
103,516 KB |
testcase_10 | AC | 133 ms
77,036 KB |
testcase_11 | AC | 822 ms
111,268 KB |
testcase_12 | AC | 447 ms
103,672 KB |
testcase_13 | AC | 676 ms
106,076 KB |
testcase_14 | AC | 293 ms
88,180 KB |
testcase_15 | AC | 135 ms
77,176 KB |
testcase_16 | AC | 356 ms
89,504 KB |
testcase_17 | AC | 384 ms
94,240 KB |
testcase_18 | AC | 175 ms
78,732 KB |
testcase_19 | AC | 396 ms
91,216 KB |
testcase_20 | AC | 271 ms
93,752 KB |
testcase_21 | AC | 193 ms
79,732 KB |
testcase_22 | AC | 567 ms
107,436 KB |
testcase_23 | AC | 237 ms
84,128 KB |
testcase_24 | AC | 184 ms
80,144 KB |
testcase_25 | AC | 115 ms
76,736 KB |
testcase_26 | AC | 405 ms
100,752 KB |
testcase_27 | AC | 495 ms
106,160 KB |
testcase_28 | AC | 455 ms
97,224 KB |
testcase_29 | AC | 229 ms
82,924 KB |
testcase_30 | AC | 281 ms
87,164 KB |
testcase_31 | AC | 252 ms
84,476 KB |
testcase_32 | AC | 780 ms
117,416 KB |
testcase_33 | AC | 36 ms
52,992 KB |
testcase_34 | AC | 36 ms
52,992 KB |
testcase_35 | AC | 36 ms
53,248 KB |
ソースコード
from heapq import heappush, heappop, heapify H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] if H==2 and W==2: exit(print(1)) color0 = [[-1]*W for _ in range(H)] color1 = [[-1]*W for _ in range(H)] color0[0][0] = 0 color1[H-1][W-1] = 1 que0 = [(A[1][0], 1, 0), (A[0][1], 0, 1)] color0[1][0] = 0 color0[0][1] = 0 que1 = [(A[H-2][W-1], H-2, W-1), (A[H-1][W-2], H-1, W-2)] color1[H-2][W-1] = 1 color1[H-1][W-2] = 1 B = [[-1]*W for _ in range(H)] B[0][0] = 0 B[H-1][W-1] = 1 heapify(que0) heapify(que1) direction = [(-1,0),(0,1),(1,0),(0,-1)] cnt = 0 while True: if cnt%2 == 0: n, h, w = heappop(que0) else: n, h, w = heappop(que1) B[h][w] = cnt%2 for dh, dw in direction: if cnt%2 == 0: if 0<=h+dh<H and 0<=w+dw<W and color0[h+dh][w+dw]==-1 and B[h+dh][w+dw]!=1: color0[h+dh][w+dw] = 0 heappush(que0, (A[h+dh][w+dw], h+dh, w+dw)) elif 0<=h+dh<H and 0<=w+dw<W and B[h+dh][w+dw] == 1: exit(print(cnt+1)) else: if 0<=h+dh<H and 0<=w+dw<W and color1[h+dh][w+dw]==-1 and B[h+dh][w+dw]!=0: color1[h+dh][w+dw] = 1 heappush(que1, (A[h+dh][w+dw], h+dh, w+dw)) elif 0<=h+dh<H and 0<=w+dw<W and B[h+dh][w+dw] == 0: exit(print(cnt+1)) cnt += 1