結果

問題 No.1037 exhausted
ユーザー KodaiKodai
提出日時 2020-04-29 18:04:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,567 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 146,180 KB
最終ジャッジ日時 2023-08-19 12:23:45
合計ジャッジ時間 16,531 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,192 KB
testcase_01 AC 79 ms
70,856 KB
testcase_02 AC 78 ms
71,152 KB
testcase_03 AC 80 ms
71,328 KB
testcase_04 AC 77 ms
71,356 KB
testcase_05 AC 79 ms
71,300 KB
testcase_06 AC 79 ms
71,256 KB
testcase_07 AC 77 ms
71,184 KB
testcase_08 AC 74 ms
71,252 KB
testcase_09 AC 72 ms
71,272 KB
testcase_10 AC 74 ms
71,100 KB
testcase_11 AC 74 ms
71,304 KB
testcase_12 AC 1,567 ms
146,180 KB
testcase_13 AC 1,462 ms
145,448 KB
testcase_14 AC 1,453 ms
143,184 KB
testcase_15 AC 1,342 ms
142,116 KB
testcase_16 AC 1,525 ms
145,480 KB
testcase_17 AC 1,565 ms
145,512 KB
testcase_18 AC 1,503 ms
143,048 KB
testcase_19 AC 1,531 ms
145,300 KB
testcase_20 AC 949 ms
110,432 KB
testcase_21 AC 630 ms
109,488 KB
testcase_22 AC 170 ms
109,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, V, L = list(map(int, input().split()))
shop_list = [list(map(int, input().split())) for i in range(N)] + [[L, 0, 0]]
dis_list = [shop_list[0][0]] + [(shop_list[i + 1][0] - shop_list[i][0])
                                for i in range(len(shop_list) - 1)]

dp_list = [[float("inf")] * (V + 1) for j in range(N + 2)]
dp_list[0][V] = 0

for n in range(N + 1):
    for v in range(dis_list[n], V + 1):
        dp_list[n + 1][v - dis_list[n]] = min([dp_list[n + 1][v - dis_list[n]], dp_list[n][v]])
        gas = min([V, v - dis_list[n] + shop_list[n][1]])
        dp_list[n + 1][gas] = min([dp_list[n + 1][gas], dp_list[n][v] + shop_list[n][2]])

ans = min(dp_list[-1])
if min(dp_list[-1]) == float("inf"):
    print(-1)
else:
    print(ans)
0