結果

問題 No.1037 exhausted
ユーザー IKyoproIKyopro
提出日時 2020-04-24 22:21:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 2,240 ms
コンパイル使用メモリ 200,584 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2024-04-23 03:32:27
合計ジャッジ時間 3,439 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

void chmin(ll &a,ll b){if(a>b) a = b;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,V,L;
    cin >> N >> V >> L;
    vec<int> x(N+2),v(N+2),w(N+2);
    for(int i=1;i<=N;i++) cin >> x[i] >> v[i] >> w[i];
    ll inf = 1e18;
    x[N+1] = L;
    vvec<ll> dp(N+2,vec<ll>(V+1,inf));
    dp[0][V] = 0;
    for(int i=1;i<=N+1;i++) for(int j=0;j<=V;j++){
        int d = x[i]-x[i-1];
        if(d<=j) chmin(dp[i][j-d],dp[i-1][j]);
        if(i!=1){
            int nj = min(V,j+v[i-1]);
            if(d<=nj) chmin(dp[i][nj-d],dp[i-1][j]+w[i-1]); 
        }
    }
    ll ans = inf;
//    for(int i=0;i<=N+1;i++) for(int j=0;j<=V;j++) cerr << dp[i][j] << (j!=V? " ":"\n");
    for(int j=0;j<=V;j++) chmin(ans,dp[N+1][j]);
    cout << (ans!=inf? ans:-1) << "\n";
}
0