結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 9 ms
35,012 KB
testcase_02 AC 8 ms
35,240 KB
testcase_03 AC 10 ms
35,280 KB
testcase_04 WA -
testcase_05 AC 10 ms
35,276 KB
testcase_06 AC 9 ms
35,104 KB
testcase_07 WA -
testcase_08 AC 8 ms
34,996 KB
testcase_09 AC 8 ms
35,136 KB
testcase_10 AC 9 ms
35,040 KB
testcase_11 WA -
testcase_12 AC 19 ms
35,140 KB
testcase_13 AC 19 ms
35,112 KB
testcase_14 AC 23 ms
35,028 KB
testcase_15 AC 19 ms
35,040 KB
testcase_16 AC 23 ms
35,116 KB
testcase_17 AC 22 ms
35,360 KB
testcase_18 AC 24 ms
35,192 KB
testcase_19 AC 18 ms
35,092 KB
testcase_20 AC 20 ms
35,204 KB
testcase_21 AC 18 ms
35,092 KB
testcase_22 AC 16 ms
35,208 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]+t && 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