結果

問題 No.1037 exhausted
ユーザー H3PO4H3PO4
提出日時 2021-10-02 13:18:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 10,764 KB
実行使用メモリ 29,792 KB
最終ジャッジ日時 2023-09-27 12:48:02
合計ジャッジ時間 4,325 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
29,536 KB
testcase_01 AC 116 ms
29,432 KB
testcase_02 AC 117 ms
29,632 KB
testcase_03 AC 121 ms
29,440 KB
testcase_04 AC 124 ms
29,676 KB
testcase_05 AC 120 ms
29,508 KB
testcase_06 AC 118 ms
29,748 KB
testcase_07 AC 116 ms
29,708 KB
testcase_08 AC 115 ms
29,472 KB
testcase_09 AC 118 ms
29,644 KB
testcase_10 AC 112 ms
29,664 KB
testcase_11 AC 113 ms
29,776 KB
testcase_12 AC 159 ms
29,792 KB
testcase_13 AC 155 ms
29,676 KB
testcase_14 AC 156 ms
29,736 KB
testcase_15 AC 163 ms
29,632 KB
testcase_16 AC 166 ms
29,700 KB
testcase_17 AC 176 ms
29,784 KB
testcase_18 AC 173 ms
29,672 KB
testcase_19 AC 165 ms
29,648 KB
testcase_20 AC 119 ms
29,728 KB
testcase_21 AC 126 ms
29,544 KB
testcase_22 AC 121 ms
29,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N, V, L = map(int, input().split())
INF = 10 ** 18
dp = np.full(V + 1, INF)
dp[V] = 0
cur = 0
for _ in range(N):
    new_dp = np.full(V + 1, INF)
    x, v, w = map(int, input().split())
    if v == 0:
        continue
    dist = x - cur
    if dist > V:
        print(-1)
        exit()
    new_dp[:V + 1 - dist] = dp[dist:]
    dp = new_dp.copy()

    if v <= V:
        new_dp[v:] = np.minimum(new_dp[v:], dp[:-v] + w)
        new_dp[V] = min(new_dp[V], np.min(dp[-v:]) + w)
    else:
        new_dp[V] = min(new_dp[V], np.min(dp) + w)

    dp = new_dp.copy()
    cur = x

if L - cur > V:
    print(-1)
    exit()
ans = np.min(dp[L - cur:])
print(ans if ans != INF else -1)
0