結果

問題 No.1037 exhausted
ユーザー autumn-eelautumn-eel
提出日時 2020-04-24 22:07:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 195,692 KB
実行使用メモリ 74,132 KB
最終ジャッジ日時 2024-04-23 03:22:35
合計ジャッジ時間 2,933 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 19 ms
74,012 KB
testcase_03 AC 19 ms
73,880 KB
testcase_04 AC 18 ms
73,888 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 18 ms
74,040 KB
testcase_07 AC 18 ms
73,988 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 18 ms
73,912 KB
testcase_10 AC 18 ms
73,916 KB
testcase_11 AC 19 ms
73,980 KB
testcase_12 AC 30 ms
74,132 KB
testcase_13 AC 28 ms
73,960 KB
testcase_14 AC 30 ms
74,132 KB
testcase_15 AC 31 ms
73,968 KB
testcase_16 AC 31 ms
73,964 KB
testcase_17 AC 30 ms
73,940 KB
testcase_18 AC 32 ms
73,944 KB
testcase_19 AC 30 ms
74,108 KB
testcase_20 AC 24 ms
73,948 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 23 ms
74,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll dp[3000][3000];
ll x[3000],v[3000],w[3000];

int main(){
	ll n,V,L;cin>>n>>V>>L;
	rep(i,n){
		scanf("%lld%lld%lld",&x[i],&v[i],&w[i]);
	}
	x[n]=L;
	if(V<x[0]){
		puts("-1");return 0;
	}
	memset(dp,0x3f,sizeof(dp));
	dp[0][V-x[0]]=0;
	rep(i,n)rep(j,V+1){
		if(dp[i][j]==INFL)continue;
		ll cost=x[i+1]-x[i];
		if(j>=cost)dp[i+1][j-cost]=min(dp[i+1][j-cost],dp[i][j]);
		if(int nj=min(V,j+v[i]);nj>=cost)dp[i+1][nj-cost]=min(dp[i+1][nj-cost],dp[i][j]+w[i]);
	}
	ll Min=INFL;
	for(int i=0;i<=V;i++){
		Min=min(Min,dp[n][i]);
	}
	if(Min==INFL)puts("-1");
	else cout<<Min<<endl;
}
0