結果

問題 No.1037 exhausted
ユーザー chocoruskchocorusk
提出日時 2020-04-24 22:20:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,241 bytes
コンパイル時間 1,259 ms
コンパイル使用メモリ 127,228 KB
実行使用メモリ 35,252 KB
最終ジャッジ日時 2024-04-23 03:31:03
合計ジャッジ時間 2,343 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 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,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 24 ms
35,096 KB
testcase_13 AC 23 ms
35,080 KB
testcase_14 AC 24 ms
35,080 KB
testcase_15 AC 23 ms
35,104 KB
testcase_16 AC 23 ms
35,160 KB
testcase_17 AC 23 ms
35,252 KB
testcase_18 AC 25 ms
35,192 KB
testcase_19 AC 23 ms
35,112 KB
testcase_20 AC 23 ms
35,092 KB
testcase_21 AC 20 ms
35,176 KB
testcase_22 AC 17 ms
35,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, V, l;
	cin>>n>>V>>l;
	int x[2020], v[2020]; ll w[2020];
	for(int i=1; i<=n; i++) cin>>x[i]>>v[i]>>w[i];
	x[0]=0, x[n+1]=l;
	v[0]=v[n+1]=0, w[0]=w[n+1]=0;
	ll dp[2020][2020];
	const ll INF=1e18;
	for(int i=0; i<=n+1; i++){
		for(int j=0; j<=V; j++) dp[i][j]=INF;
	}
	dp[0][V]=0;
	for(int i=0; i<=n; i++){
		for(int j=0; j<=V; j++){
			if(j-(x[i+1]-x[i])>=0){
				dp[i+1][j-(x[i+1]-x[i])]=min(dp[i+1][j-(x[i+1]-x[i])], dp[i][j]);
				dp[i+1][min(V, j-(x[i+1]-x[i])+v[i+1])]=min(dp[i+1][min(V, j-(x[i+1]-x[i])+v[i+1])], dp[i][j]+w[i+1]);
			}
		}
	}
	ll ans=INF;
	for(int i=0; i<=V; i++) ans=min(ans, dp[n+1][i]);
	if(ans>=INF/2) cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}
0