結果

問題 No.1037 exhausted
ユーザー kappybarkappybar
提出日時 2020-04-25 20:29:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,160 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 172,684 KB
実行使用メモリ 34,392 KB
最終ジャッジ日時 2023-08-07 14:51:56
合計ジャッジ時間 2,975 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 40 ms
34,184 KB
testcase_13 AC 40 ms
34,180 KB
testcase_14 AC 40 ms
34,140 KB
testcase_15 AC 40 ms
34,208 KB
testcase_16 AC 40 ms
34,220 KB
testcase_17 AC 40 ms
34,144 KB
testcase_18 AC 39 ms
34,164 KB
testcase_19 AC 39 ms
34,216 KB
testcase_20 AC 39 ms
34,168 KB
testcase_21 AC 39 ms
34,248 KB
testcase_22 AC 37 ms
34,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const ll INF = 1e10;
const int MOD = 1000000007;

struct gas{
    int x,v,w;
};

int main(){
    int N,V,L;
    cin >> N >> V >> L;
    vector<gas> gass(N);
    rep(i,N) cin >> gass[i].x >> gass[i].v >> gass[i].w;
    vector<vector<ll>> dp(N+1,vector<ll>(V+1,INF));
    dp[0][V] = 0;
    for(int i=1;i<=N;i++){
        ll d = (i==1 ? gass[i-1].x : gass[i-1].x - gass[i-2].x);
        ll mn = INF;
        rep(j,V+1){
            if(d+V-gass[i-1].v <= j && V - gass[i-1].v >= 0) mn = min(mn,dp[i-1][j]);

            if(j+d <= V) dp[i][j] = dp[i-1][j+d];
            if(j-gass[i-1].v >= 0 && j+d-gass[i-1].v <= V) dp[i][j] = min(dp[i][j],dp[i-1][j+d-gass[i-1].v] + gass[i-1].w);
            if(j==V) dp[i][j] = min(dp[i][j],mn + gass[i-1].w);
        }
    }
    ll d = L - gass[N-1].x;
    ll ans = INF;
    for(ll i=d;i<=V;i++){
        ans = min(ans,dp[N][i]);
    }  
    cout << (ans==INF ? -1 : ans) << endl;
    /*
    rep(i,N+1){
        rep(j,V+1) cout << dp[i][j] << " ";
        cout << endl;
    }*/
    return 0;
}
0