結果

問題 No.1037 exhausted
ユーザー trineutrontrineutron
提出日時 2020-04-24 22:29:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,319 bytes
コンパイル時間 2,393 ms
コンパイル使用メモリ 202,828 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2024-04-23 03:39:12
合計ジャッジ時間 3,782 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 56 ms
34,560 KB
testcase_13 AC 56 ms
34,432 KB
testcase_14 AC 56 ms
34,560 KB
testcase_15 AC 56 ms
34,432 KB
testcase_16 AC 55 ms
34,432 KB
testcase_17 AC 56 ms
34,560 KB
testcase_18 AC 56 ms
34,432 KB
testcase_19 AC 56 ms
34,304 KB
testcase_20 AC 49 ms
34,432 KB
testcase_21 AC 45 ms
34,688 KB
testcase_22 AC 34 ms
34,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    constexpr int64_t inf = 1e18;
    int n, vmax, l;
    cin >> n >> vmax >> l;
    vector<int> x(n + 2), v(n + 2), w(n + 2);
    for (int i = 0; i < n; i++) {
        cin >> x.at(i + 1) >> v.at(i + 1) >> w.at(i + 1);
    }
    x.at(n + 1) = l;
    vector<vector<int64_t>> dp(n + 2, vector<int64_t>(vmax + 1, inf)); // remaining, cost
    dp.at(0).at(vmax) = 0;
    for (int i = 0; i <= n; i++) {
        int used = x.at(i + 1) - x.at(i);
        for (int j = 0; j <= vmax; j++) {
            int prev_j = j + used, prev_j_stop = prev_j - v.at(i + 1);
            if (prev_j <= vmax) {
                dp.at(i + 1).at(j) = min(dp.at(i + 1).at(j), dp.at(i).at(prev_j));
            }
            if (prev_j_stop >= used && prev_j_stop <= vmax) {
                dp.at(i + 1).at(j) = min(dp.at(i + 1).at(j), dp.at(i).at(prev_j_stop) + w.at(i + 1));
            }
        }
        for (int j = vmax + used - v.at(i + 1); j <= vmax; j++) {
            dp.at(i + 1).at(vmax) = min(dp.at(i + 1).at(vmax), dp.at(i).at(j) + w.at(i + 1));
        }
    }
    int64_t ans = inf;
    for (int i = 0; i <= vmax; i++) {
        ans = min(ans, dp.at(n + 1).at(i));
    }
    if (ans == inf) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}
0