結果
問題 | No.2731 Two Colors |
ユーザー | detteiuu |
提出日時 | 2024-04-19 21:57:40 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,017 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 81,880 KB |
実行使用メモリ | 114,212 KB |
最終ジャッジ日時 | 2024-04-19 21:58:15 |
合計ジャッジ時間 | 16,317 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 91 ms
76,744 KB |
testcase_04 | WA | - |
testcase_05 | AC | 131 ms
78,312 KB |
testcase_06 | AC | 204 ms
82,224 KB |
testcase_07 | WA | - |
testcase_08 | AC | 109 ms
77,456 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 247 ms
86,656 KB |
testcase_15 | AC | 112 ms
77,216 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 95 ms
76,428 KB |
testcase_26 | AC | 372 ms
96,324 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 246 ms
84,684 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 35 ms
54,308 KB |
testcase_34 | AC | 35 ms
53,220 KB |
testcase_35 | AC | 35 ms
52,560 KB |
ソースコード
from heapq import heappush, heappop, heapify H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] color = [[-1]*W for _ in range(H)] color[0][0] = 0 color[H-1][W-1] = 1 que0 = [(A[1][0], 1, 0), (A[0][1], 0, 1)] color[1][0] = 0 color[0][1] = 0 que1 = [(A[H-2][W-1], H-2, W-1), (A[H-1][W-2], H-1, W-2)] color[H-2][W-1] = 1 color[H-1][W-2] = 1 B = [[-1]*W for _ in range(H)] 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 0<=h+dh<H and 0<=w+dw<W and color[h+dh][w+dw]==-1: color[h+dh][w+dw] = cnt%2 if cnt%2 == 0: heappush(que0, (A[h+dh][w+dw], h+dh, w+dw)) else: 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] == (cnt%2)^1: exit(print(cnt+1)) cnt += 1