結果

問題 No.1037 exhausted
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-04-24 22:59:31
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 381 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 138,112 KB
最終ジャッジ日時 2023-08-05 05:56:31
合計ジャッジ時間 5,466 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,252 KB
testcase_01 AC 71 ms
71,280 KB
testcase_02 AC 70 ms
71,404 KB
testcase_03 AC 72 ms
71,216 KB
testcase_04 AC 72 ms
71,476 KB
testcase_05 AC 72 ms
71,248 KB
testcase_06 AC 75 ms
71,544 KB
testcase_07 AC 72 ms
71,228 KB
testcase_08 AC 71 ms
71,372 KB
testcase_09 AC 72 ms
71,480 KB
testcase_10 AC 72 ms
71,368 KB
testcase_11 AC 73 ms
71,140 KB
testcase_12 AC 334 ms
123,124 KB
testcase_13 AC 316 ms
128,592 KB
testcase_14 AC 327 ms
128,624 KB
testcase_15 AC 314 ms
133,100 KB
testcase_16 AC 381 ms
138,112 KB
testcase_17 AC 323 ms
128,664 KB
testcase_18 AC 334 ms
126,140 KB
testcase_19 AC 336 ms
124,648 KB
testcase_20 AC 278 ms
110,200 KB
testcase_21 AC 188 ms
109,144 KB
testcase_22 AC 171 ms
109,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
dpだろうね
N,Vが小さいので、これでdpか?

dp[i番目のgsに来た時][燃料残量] = 最小のコスト
"""

N,V,L = map(int,input().split())

dp = [[float("inf")] * (V+1) for i in range(N+2)]
dp[0][V] = 0
lastx = 0

for i in range(N+1):

    if i == N:
        x = L
        v = 0
        w = 0

    else:
        x,v,w = map(int,input().split())



    for j in range(V-(x-lastx)+1):

        dp[i+1][j] = dp[i][j+x-lastx]

    for j in range(V,-1,-1):

        dp[i+1][min(V,j+v)] = min(dp[i+1][min(V,j+v)] , dp[i+1][j] + w)

    lastx = x

ans = min(dp[-1])

if ans == float("inf"):
    print (-1)
else:
    print (ans)
0