結果
| 問題 | No.2731 Two Colors |
| コンテスト | |
| ユーザー |
detteiuu
|
| 提出日時 | 2024-04-19 21:52:51 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,045 bytes |
| 記録 | |
| コンパイル時間 | 294 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 113,832 KB |
| 最終ジャッジ日時 | 2024-10-11 14:52:49 |
| 合計ジャッジ時間 | 19,499 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)]
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
detteiuu