結果

問題 No.1037 exhausted
ユーザー NrKmDevNrKmDev
提出日時 2020-04-25 11:42:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,427 bytes
コンパイル時間 2,918 ms
コンパイル使用メモリ 200,096 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2024-04-24 13:20:16
合計ジャッジ時間 3,356 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド:(典型)dp,dfs,bfs,最短経路,その他
int main(){
    ll n,V,l;cin>>n>>V>>l;
    vl x(n),v(n),w(n);rep(i,n)cin>>x[i]>>v[i]>>w[i];
    vector<vl> dp(n+2,vl(V+1,LINF));
    dp[0][V]=0;
    ll d;
    rep(i,n+1){
        if(i==0)d=x[i];
        else if(i==n)d=l-x[i-1];
        else d=x[i]-x[i-1];
        rep(j,V+1){
            if(dp[i][j]!=LINF&&j>=d){
                chmin(dp[i+1][min(V,j-d+v[i])],dp[i][j]+w[i]);
                chmin(dp[i+1][j-d],dp[i][j]);
            }
        }
    }
    ll ans=LINF;
    rep(i,V+1)chmin(ans,dp[n+1][i]);
    if(ans==LINF){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;
}
0