結果

問題 No.1037 exhausted
ユーザー t98slidert98slider
提出日時 2023-05-22 02:18:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 1,513 ms
コンパイル使用メモリ 171,844 KB
実行使用メモリ 34,448 KB
最終ジャッジ日時 2023-08-23 16:21:32
合計ジャッジ時間 3,027 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 37 ms
34,424 KB
testcase_13 AC 37 ms
34,332 KB
testcase_14 AC 37 ms
34,212 KB
testcase_15 AC 37 ms
34,108 KB
testcase_16 AC 37 ms
34,236 KB
testcase_17 AC 37 ms
34,364 KB
testcase_18 AC 37 ms
34,164 KB
testcase_19 AC 38 ms
34,196 KB
testcase_20 AC 36 ms
34,196 KB
testcase_21 AC 35 ms
34,448 KB
testcase_22 AC 30 ms
34,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, V, L;
    cin >> n >> V >> L;
    vector<int> x(n + 2), v(n + 1), w(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> x[i] >> v[i] >> w[i];
    }
    x[n + 1] = L;
    vector<vector<ll>> dp(n + 2, vector<ll>(V + 1, 1ll << 60));
    dp[0][V] = 0;
    for(int i = 0; i <= n; i++){
        int d = x[i + 1] - x[i];
        for(int j = 0; j <= V; j++){
            int nj = min(V, j + v[i]);
            if(nj >= d) dp[i + 1][nj - d] = min(dp[i + 1][nj - d], dp[i][j] + w[i]);
            if(j >= d) dp[i + 1][j - d] = min(dp[i + 1][j - d], dp[i][j]);
        }
    }
    ll ans = *min_element(dp.back().begin(), dp.back().end());
    cout << (ans >> 60 ? -1 : ans) << '\n';
}
0