結果

問題 No.2328 Build Walls
ユーザー ntudantuda
提出日時 2023-06-08 22:29:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 760 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 83,952 KB
最終ジャッジ日時 2023-08-30 01:51:23
合計ジャッジ時間 9,677 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,152 KB
testcase_01 AC 69 ms
71,304 KB
testcase_02 AC 71 ms
71,344 KB
testcase_03 AC 70 ms
71,304 KB
testcase_04 AC 71 ms
71,032 KB
testcase_05 AC 70 ms
71,356 KB
testcase_06 AC 70 ms
71,032 KB
testcase_07 AC 71 ms
71,348 KB
testcase_08 AC 71 ms
71,356 KB
testcase_09 AC 69 ms
71,032 KB
testcase_10 AC 71 ms
71,032 KB
testcase_11 AC 70 ms
71,228 KB
testcase_12 AC 71 ms
71,228 KB
testcase_13 AC 154 ms
80,308 KB
testcase_14 WA -
testcase_15 AC 152 ms
79,368 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 91 ms
76,900 KB
testcase_20 WA -
testcase_21 AC 125 ms
80,356 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 155 ms
83,116 KB
testcase_29 WA -
testcase_30 AC 201 ms
83,324 KB
testcase_31 AC 186 ms
83,176 KB
testcase_32 WA -
testcase_33 AC 176 ms
83,332 KB
testcase_34 AC 197 ms
83,268 KB
testcase_35 AC 215 ms
83,412 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H - 2)]
INF = 10 ** 6

dp = [INF] * (H - 2)
for i in range(H - 2):
    if A[i][0] != -1:
        dp[i] = A[i][0]

for i in range(1, W):
    dp2 = [INF] * (H - 2)
    for j in range(H - 2):
        a = A[j][i]
        if a != -1:
            dp2[j] = min(dp2[j], dp[j] + a)
            if 0 < j:
                dp2[j] = min(dp2[j], dp[j - 1] + a)
                dp2[j] = min(dp2[j], dp2[j - 1] + a)
            if j < H - 3:
                dp2[j] = min(dp2[j], dp[j + 1] + a)
    for j in reversed(range(H - 3)):
        a = A[j][i]
        if a != -1:
            dp2[j] = min(dp2[j], dp2[j + 1] + a)
    dp = dp2

if min(dp) < INF:
    print(min(dp))
else:
    print(-1)
0