結果

問題 No.2328 Build Walls
ユーザー masa_aamasa_aa
提出日時 2023-05-28 14:51:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 501 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 88,564 KB
最終ジャッジ日時 2023-08-27 10:44:18
合計ジャッジ時間 6,853 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,636 KB
testcase_01 AC 64 ms
71,316 KB
testcase_02 AC 64 ms
71,624 KB
testcase_03 AC 64 ms
71,268 KB
testcase_04 AC 66 ms
71,520 KB
testcase_05 AC 64 ms
71,520 KB
testcase_06 AC 63 ms
71,132 KB
testcase_07 AC 63 ms
71,156 KB
testcase_08 AC 64 ms
71,572 KB
testcase_09 AC 64 ms
71,132 KB
testcase_10 AC 64 ms
71,316 KB
testcase_11 AC 64 ms
71,368 KB
testcase_12 AC 66 ms
71,312 KB
testcase_13 AC 128 ms
80,172 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 84 ms
76,712 KB
testcase_20 WA -
testcase_21 AC 115 ms
82,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 135 ms
82,072 KB
testcase_29 WA -
testcase_30 AC 179 ms
88,348 KB
testcase_31 AC 171 ms
87,872 KB
testcase_32 WA -
testcase_33 AC 166 ms
88,216 KB
testcase_34 AC 177 ms
88,084 KB
testcase_35 AC 183 ms
87,952 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = map(int, input().split())
h -= 2
a = [list(map(int, input().split())) for _ in range(h)]
INF = 10**18
dp = [[INF] * w for _ in range(h)] + [[INF] * w]

for i in range(h):
    if a[i][0] == -1:
        continue
    dp[i][0] = a[i][0]

for j in range(w - 1):
    for i in range(h):
        if a[i][j + 1] == -1:
            continue
        dp[i][j + 1] = min(dp[i - 1][j], dp[i][j], dp[i + 1][j]) + a[i][j + 1]
ans = min(v[-1] for v in dp)
print(ans if ans < INF else -1)
# print(*dp, sep="\n")
0