結果

問題 No.2328 Build Walls
ユーザー lloyzlloyz
提出日時 2024-01-19 08:41:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,106 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 87,672 KB
最終ジャッジ日時 2024-01-19 08:41:57
合計ジャッジ時間 10,305 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 36 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 37 ms
53,460 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 36 ms
53,460 KB
testcase_10 AC 37 ms
53,460 KB
testcase_11 AC 36 ms
53,460 KB
testcase_12 AC 36 ms
53,460 KB
testcase_13 AC 127 ms
79,864 KB
testcase_14 WA -
testcase_15 AC 154 ms
79,236 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 54 ms
70,444 KB
testcase_20 WA -
testcase_21 AC 91 ms
80,760 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 116 ms
80,504 KB
testcase_29 WA -
testcase_30 AC 160 ms
86,776 KB
testcase_31 AC 157 ms
87,288 KB
testcase_32 WA -
testcase_33 AC 326 ms
87,416 KB
testcase_34 AC 164 ms
87,416 KB
testcase_35 AC 319 ms
87,288 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:
                DP[ni][j + 1] = min(DP[ni][j + 1], DP[i][j] + A[ni][j + 1])
            if A[ni][j] != -1:
                DP[ni][j] = min(DP[ni][j], DP[i][j] + A[ni][j])
    for i in range(h - 1, -1, -1):
        if DP[i][j] == INF:
            continue
        for di in (-1, 0, 1):
            ni = i + di
            if A[ni][j + 1] != -1:
                DP[ni][j + 1] = min(DP[ni][j + 1], DP[i][j] + A[ni][j + 1])
            if A[ni][j] != -1:
                DP[ni][j] = min(DP[ni][j], DP[i][j] + A[ni][j])
ans = INF
for i in range(h):
    ans = min(ans, DP[i][w - 1])
if ans == INF:
    ans = -1
print(ans)
0