結果

問題 No.1037 exhausted
ユーザー hedwig100hedwig100
提出日時 2020-04-24 23:27:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 938 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 104,064 KB
最終ジャッジ日時 2024-04-23 04:18:05
合計ジャッジ時間 4,071 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,760 KB
testcase_01 AC 44 ms
54,016 KB
testcase_02 AC 43 ms
53,888 KB
testcase_03 AC 45 ms
53,760 KB
testcase_04 AC 42 ms
54,272 KB
testcase_05 AC 42 ms
53,888 KB
testcase_06 AC 43 ms
53,760 KB
testcase_07 AC 42 ms
54,016 KB
testcase_08 AC 43 ms
54,144 KB
testcase_09 AC 42 ms
54,272 KB
testcase_10 AC 43 ms
54,016 KB
testcase_11 AC 44 ms
54,528 KB
testcase_12 AC 230 ms
103,360 KB
testcase_13 AC 229 ms
103,572 KB
testcase_14 AC 226 ms
103,936 KB
testcase_15 AC 231 ms
103,808 KB
testcase_16 AC 227 ms
103,796 KB
testcase_17 AC 229 ms
103,424 KB
testcase_18 AC 226 ms
103,424 KB
testcase_19 AC 227 ms
103,424 KB
testcase_20 AC 243 ms
104,064 KB
testcase_21 AC 196 ms
103,168 KB
testcase_22 AC 181 ms
103,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 16
MOD = 10 **9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque
from math import factorial

def main():
    n,V,L = map(int,input().split())
    Gas = [(0,0,INF)] + [tuple(map(int,input().split())) for _ in range(n)] + [(L,0,INF)]
    
    dp = [[0] * (V + 1)] + [[INF] * (V + 1) for _ in range(n + 1)]
    for i in range(n + 1):
        before_x,before_v,before_w = Gas[i]
        x,v,w = Gas[i + 1]
        for j in range(V + 1):      
            if min(j + before_v,V) - x + before_x >= 0: 
                dp[i + 1][min(j + before_v,V) - x + before_x] = min(dp[i + 1][min(j + before_v,V) - x + before_x],dp[i][j] + before_w)
            if j - x + before_x >= 0:
                dp[i + 1][j - x + before_x] = min(dp[i + 1][j - x + before_x],dp[i][j])
    ans = min(dp[-1])
    print(ans if ans != INF else -1)            
if __name__=='__main__':
    main()
0