結果
問題 |
No.2731 Two Colors
|
ユーザー |
![]() |
提出日時 | 2024-04-19 21:57:40 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,017 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 113,700 KB |
最終ジャッジ日時 | 2024-10-11 15:03:22 |
合計ジャッジ時間 | 18,022 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 WA * 24 |
ソースコード
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