結果

問題 No.2328 Build Walls
ユーザー lloyzlloyz
提出日時 2024-01-17 07:22:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 688 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 86,648 KB
最終ジャッジ日時 2024-01-17 07:23:02
合計ジャッジ時間 7,883 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 39 ms
53,460 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 38 ms
53,460 KB
testcase_10 AC 37 ms
53,460 KB
testcase_11 AC 37 ms
53,460 KB
testcase_12 AC 40 ms
53,460 KB
testcase_13 AC 103 ms
79,224 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 54 ms
68,228 KB
testcase_20 WA -
testcase_21 AC 89 ms
80,632 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 119 ms
80,504 KB
testcase_29 WA -
testcase_30 AC 136 ms
86,392 KB
testcase_31 AC 127 ms
80,632 KB
testcase_32 WA -
testcase_33 AC 212 ms
86,648 KB
testcase_34 AC 135 ms
86,392 KB
testcase_35 AC 205 ms
86,392 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = map(int, input().split())
A = []
A.append([-1 for _ in range(w)])
for _ in range(h - 2):
    A.append(list(map(int, input().split())))
A.append([-1 for _ in range(w)])

INF = 10**18
DP = [[INF for _ in range(w)] for _ in range(h)]
for i in range(h):
    if A[i][0] != -1:
        DP[i][0] = A[i][0]
for j in range(w - 1):
    for i in range(h):
        if DP[i][j] == INF:
            continue
        for di in (-1, 0, 1):
            ni = i + di
            if A[ni][j + 1] == -1:
                continue
            DP[ni][j + 1] = min(DP[ni][j + 1], DP[i][j] + A[ni][j + 1])
ans = INF
for i in range(h):
    ans = min(ans, DP[i][w - 1])
if ans == INF:
    ans = -1
print(ans)
0