結果
問題 | No.2731 Two Colors |
ユーザー | detteiuu |
提出日時 | 2024-04-19 22:16:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,560 ms / 3,000 ms |
コード長 | 1,372 bytes |
コンパイル時間 | 254 ms |
コンパイル使用メモリ | 82,012 KB |
実行使用メモリ | 119,592 KB |
最終ジャッジ日時 | 2024-10-11 15:42:29 |
合計ジャッジ時間 | 18,496 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,560 ms
119,228 KB |
testcase_01 | AC | 1,557 ms
119,592 KB |
testcase_02 | AC | 1,558 ms
119,580 KB |
testcase_03 | AC | 106 ms
77,056 KB |
testcase_04 | AC | 144 ms
79,448 KB |
testcase_05 | AC | 155 ms
78,336 KB |
testcase_06 | AC | 240 ms
83,800 KB |
testcase_07 | AC | 209 ms
83,396 KB |
testcase_08 | AC | 130 ms
78,400 KB |
testcase_09 | AC | 451 ms
103,640 KB |
testcase_10 | AC | 120 ms
76,928 KB |
testcase_11 | AC | 836 ms
111,156 KB |
testcase_12 | AC | 442 ms
103,924 KB |
testcase_13 | AC | 710 ms
106,200 KB |
testcase_14 | AC | 288 ms
88,428 KB |
testcase_15 | AC | 134 ms
77,696 KB |
testcase_16 | AC | 381 ms
89,504 KB |
testcase_17 | AC | 412 ms
94,216 KB |
testcase_18 | AC | 180 ms
79,108 KB |
testcase_19 | AC | 410 ms
90,956 KB |
testcase_20 | AC | 298 ms
94,296 KB |
testcase_21 | AC | 199 ms
79,984 KB |
testcase_22 | AC | 608 ms
107,412 KB |
testcase_23 | AC | 260 ms
83,980 KB |
testcase_24 | AC | 189 ms
80,176 KB |
testcase_25 | AC | 114 ms
76,604 KB |
testcase_26 | AC | 437 ms
100,640 KB |
testcase_27 | AC | 534 ms
106,412 KB |
testcase_28 | AC | 502 ms
97,316 KB |
testcase_29 | AC | 244 ms
83,060 KB |
testcase_30 | AC | 290 ms
87,556 KB |
testcase_31 | AC | 279 ms
84,472 KB |
testcase_32 | AC | 831 ms
117,412 KB |
testcase_33 | AC | 39 ms
52,992 KB |
testcase_34 | AC | 39 ms
52,864 KB |
testcase_35 | AC | 39 ms
52,864 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