結果

問題 No.1037 exhausted
ユーザー kibunakibuna
提出日時 2020-04-24 22:40:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,193 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 170,400 KB
実行使用メモリ 34,568 KB
最終ジャッジ日時 2023-08-05 05:28:04
合計ジャッジ時間 2,924 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 39 ms
34,528 KB
testcase_13 AC 40 ms
34,104 KB
testcase_14 AC 39 ms
34,096 KB
testcase_15 AC 39 ms
34,556 KB
testcase_16 AC 40 ms
34,132 KB
testcase_17 AC 39 ms
34,396 KB
testcase_18 AC 41 ms
34,568 KB
testcase_19 AC 41 ms
34,520 KB
testcase_20 AC 40 ms
34,196 KB
testcase_21 AC 39 ms
34,364 KB
testcase_22 AC 38 ms
34,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, V, L;
    cin >> n >> V >> L;
    vector<lint> x(n + 2), v(n + 2), w(n + 2);
    for (int i = 1; i <= n; ++i) {
        cin >> x[i] >> v[i] >> w[i];
    }
    x[n + 1] = L;
    v[n + 1] = 0;
    w[n + 1] = 0;
    vector<vector<lint>> dp(n + 2, (vector<lint>(V + 1, inf)));
    dp[0][V] = 0;
    for (int i = 1; i <= n + 1; ++i) {
        for (int j = 0; j <= V; ++j) {
            if (j + (x[i] - x[i - 1]) <= V)
                chmin(dp[i][j], dp[i - 1][j + (x[i] - x[i - 1])]);
        }
        for (int j = V; j >= 0; --j) {
            chmin(dp[i][min(V, j + v[i])], dp[i][j] + w[i]);
        }
    }
    lint ret = inf;
    for (int j = 0; j <= V; ++j) {
        chmin(ret, dp[n + 1][j]);
    }
    if (ret == inf)
        cout << -1 << "\n";
    else
        cout << ret << "\n";
    return 0;
}
0