結果

問題 No.2328 Build Walls
ユーザー Ayuna
提出日時 2023-05-28 13:53:46
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 659 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 906,180 KB
最終ジャッジ日時 2024-12-26 22:12:52
合計ジャッジ時間 64,301 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 MLE * 2
other AC * 11 TLE * 13 MLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
h, w = map(int, input().split())
a = [[] for _ in range(h - 2)]
for i in range(h - 2):
    a[i] = list(map(int, input().split()))
ans = 1 << 29
for i in range(h - 2):
    if a[i][0] == -1: continue
    q = deque()
    q.append((i, 0, a[i][0]))
    while q:
        tate, yoko, cost = q.popleft()
        if yoko == w - 1:
            if ans > cost:
                ans = cost
            continue
        for j in range(-1, 2):
            if h - 3 >= tate + j >= 0 and a[tate + j][yoko + 1] != -1:
                q.append((tate + j, yoko + 1, cost + a[tate + j][yoko + 1]))
if ans == 1 << 29:
    print(-1)
else:
    print(ans)
0