結果

問題 No.1037 exhausted
ユーザー ace_amuroace_amuro
提出日時 2024-04-12 12:36:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,594 bytes
コンパイル時間 1,262 ms
コンパイル使用メモリ 84,192 KB
実行使用メモリ 35,236 KB
最終ジャッジ日時 2024-04-12 12:36:34
合計ジャッジ時間 2,660 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
35,008 KB
testcase_01 AC 11 ms
35,136 KB
testcase_02 AC 11 ms
35,028 KB
testcase_03 AC 11 ms
35,116 KB
testcase_04 AC 11 ms
35,168 KB
testcase_05 AC 11 ms
35,068 KB
testcase_06 AC 11 ms
35,236 KB
testcase_07 AC 11 ms
35,224 KB
testcase_08 AC 11 ms
35,180 KB
testcase_09 AC 12 ms
35,052 KB
testcase_10 AC 11 ms
35,208 KB
testcase_11 AC 10 ms
35,160 KB
testcase_12 AC 26 ms
35,152 KB
testcase_13 AC 25 ms
35,192 KB
testcase_14 AC 25 ms
35,164 KB
testcase_15 AC 24 ms
35,104 KB
testcase_16 AC 25 ms
35,108 KB
testcase_17 AC 25 ms
35,120 KB
testcase_18 AC 26 ms
35,088 KB
testcase_19 AC 25 ms
35,056 KB
testcase_20 AC 26 ms
34,988 KB
testcase_21 AC 26 ms
35,152 KB
testcase_22 AC 22 ms
35,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<ctime>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long LL;
const int MR=2e3+10;
int n,V,L;
int x[MR],v[MR],w[MR];
LL dp[MR][MR];
//dp[i][j]是从加油站i出发时,油量恰好等于j时的最少花费
int main(){
    cin>>n>>V>>L;
    for(int i=1;i<=n;i++){
        cin>>x[i]>>v[i]>>w[i];
    }
    x[n+1]=L;
    memset(dp,0x3f,sizeof(dp));
    dp[0][V]=0;
    for(int i=1;i<=n+1;i++){
        int t=x[i]-x[i-1];//先计算从上个加油站过来需要多少油
        for(int j=0;j<V;j++){
            //不加油直接出发,说明从上个加油站出发时有j+t升油
            if(j+t<=V) dp[i][j]=min(dp[i][j],dp[i-1][j+t]);
            //加油后出发,那么加油前有j-v[i]升,说明从上个加油站出发时有j-v[i]+t升油
            if(0<=j-v[i] && j-v[i]+t<=V){
                dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]+t]+w[i]);
            }
        }
        //但是如果加油站i出发时,油箱是满的
        //有可能两个加油站坐标一样,且没加油
        if(t==0) dp[i][V]=min(dp[i][V],dp[i-1][V]);
        //或者油箱加满了油,那么到达加油站i时的油量在 V-v[i] 到 V 都有可能
        for(int k=max(0,V-v[i]);k<=V;k++){
            if(k+t<=V) dp[i][V]=min(dp[i][V],dp[i-1][k+t]+w[i]);
        }
    }
    LL ans=1e18;
    for(int j=0;j<=V;j++) ans=min(ans,dp[n+1][j]);
    if(ans<1e18) cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0;
}
0