結果
問題 | No.2731 Two Colors |
ユーザー | detteiuu |
提出日時 | 2024-04-19 21:52:51 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,045 bytes |
コンパイル時間 | 157 ms |
コンパイル使用メモリ | 82,104 KB |
実行使用メモリ | 114,380 KB |
最終ジャッジ日時 | 2024-04-19 21:53:32 |
合計ジャッジ時間 | 18,230 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 116 ms
76,644 KB |
testcase_04 | WA | - |
testcase_05 | AC | 148 ms
78,208 KB |
testcase_06 | AC | 229 ms
82,364 KB |
testcase_07 | WA | - |
testcase_08 | AC | 127 ms
77,052 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 278 ms
86,160 KB |
testcase_15 | AC | 129 ms
77,380 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 | 111 ms
76,512 KB |
testcase_26 | AC | 442 ms
95,844 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 273 ms
84,544 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 38 ms
52,736 KB |
testcase_34 | AC | 41 ms
52,992 KB |
testcase_35 | AC | 40 ms
52,752 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)] 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 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