結果

問題 No.1037 exhausted
ユーザー 沙耶花沙耶花
提出日時 2020-04-24 22:06:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,075 bytes
コンパイル時間 2,406 ms
コンパイル使用メモリ 202,876 KB
実行使用メモリ 34,944 KB
最終ジャッジ日時 2024-04-23 03:21:42
合計ジャッジ時間 3,688 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000001


int main(){
	
	int N,V,L;
	cin>>N>>V>>L;
	
	vector<int> x,v,w;
	x.push_back(0);
	v.push_back(0);
	w.push_back(0);
	
	for(int i=0;i<N;i++){
		int a,b,c;
		cin>>a>>b>>c;
		x.push_back(a);
		v.push_back(b);
		w.push_back(c);
	}
	
	x.push_back(L);
	v.push_back(0);
	w.push_back(0);
	
	N = x.size();
	
	vector<vector<long long>> dp(N,vector<long long>(V+1,Inf));
	dp[0][V] = 0;
	
	for(int i=0;i<N-1;i++){
		for(int j=V;j>=0;j--){
			int to = min(j+v[i],V);
			dp[i][to] = min(dp[i][to],dp[i][j]+w[i]);
		}
		
		for(int j=0;j<=V;j++){
			if(dp[i][j]==Inf)continue;
			int to = j - (x[i+1]-x[i]);
			if(to<0)continue;
			dp[i+1][to] = min(dp[i+1][to],dp[i][j]);
		}
	}
	/*
	for(int i=0;i<N;i++){
		for(int j=0;j<=V;j++){
			cout<<dp[i][j]<<',';
		}
		cout<<endl;
	}
		*/
	long long ans = Inf;
	for(int i=0;i<=V;i++){
		ans = min(ans,dp.back()[i]);
	}
	
	if(ans==Inf)cout<<-1<<endl;
	else cout<<ans<<endl;
		
	return 0;
}
0