結果

問題 No.2328 Build Walls
ユーザー ntudantuda
提出日時 2023-06-08 22:44:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 787 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 84,024 KB
最終ジャッジ日時 2023-08-30 01:58:07
合計ジャッジ時間 7,566 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,148 KB
testcase_01 AC 69 ms
71,316 KB
testcase_02 AC 71 ms
71,164 KB
testcase_03 AC 70 ms
71,576 KB
testcase_04 AC 70 ms
71,484 KB
testcase_05 AC 68 ms
71,468 KB
testcase_06 AC 69 ms
71,056 KB
testcase_07 AC 69 ms
71,540 KB
testcase_08 AC 69 ms
71,364 KB
testcase_09 AC 69 ms
71,360 KB
testcase_10 AC 69 ms
71,316 KB
testcase_11 AC 70 ms
71,208 KB
testcase_12 AC 69 ms
71,520 KB
testcase_13 AC 166 ms
80,236 KB
testcase_14 WA -
testcase_15 AC 152 ms
79,264 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 90 ms
76,828 KB
testcase_20 WA -
testcase_21 AC 124 ms
80,200 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 154 ms
82,992 KB
testcase_29 WA -
testcase_30 AC 202 ms
83,172 KB
testcase_31 AC 183 ms
83,040 KB
testcase_32 WA -
testcase_33 AC 171 ms
83,260 KB
testcase_34 AC 197 ms
83,216 KB
testcase_35 AC 212 ms
83,600 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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
    # print(dp)

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