結果

問題 No.1037 exhausted
ユーザー Y17Y17
提出日時 2020-04-24 22:39:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 164,396 KB
実行使用メモリ 35,328 KB
最終ジャッジ日時 2024-04-23 03:42:33
合計ジャッジ時間 2,838 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
35,168 KB
testcase_01 AC 11 ms
35,296 KB
testcase_02 AC 10 ms
35,296 KB
testcase_03 AC 11 ms
35,192 KB
testcase_04 AC 10 ms
35,000 KB
testcase_05 AC 10 ms
35,264 KB
testcase_06 AC 10 ms
35,208 KB
testcase_07 AC 10 ms
35,080 KB
testcase_08 AC 10 ms
35,136 KB
testcase_09 AC 10 ms
35,160 KB
testcase_10 AC 10 ms
35,168 KB
testcase_11 AC 10 ms
35,012 KB
testcase_12 AC 56 ms
35,328 KB
testcase_13 AC 58 ms
35,188 KB
testcase_14 AC 61 ms
35,152 KB
testcase_15 AC 56 ms
35,328 KB
testcase_16 AC 64 ms
35,276 KB
testcase_17 AC 61 ms
35,316 KB
testcase_18 AC 68 ms
35,284 KB
testcase_19 AC 62 ms
35,264 KB
testcase_20 AC 12 ms
35,268 KB
testcase_21 AC 13 ms
35,060 KB
testcase_22 AC 11 ms
35,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int inf = 3000ll*1000000000ll;
int n, V, l;
int x[2010];
int v[2010];
int w[2010];
int memo[2010][2010];

int dp(int i, int noko){
	if(noko < 0) return inf;
	if(i == n) return 0;
	if(memo[i][noko] != -1) return memo[i][noko];
	return memo[i][noko] = min(
		dp(i+1, noko-(x[i+1]-x[i])),
		dp(i+1, min(noko+v[i], V)-(x[i+1]-x[i]))+w[i]
	);
}

signed main(){
	cin >> n >> V >> l;

	for(int i = 0;i < n;i++){
		cin >> x[i] >> v[i] >> w[i];
	}
	x[n] = l;

	memset(memo, -1, sizeof(memo));

	int ans = dp(0, V-x[0]);

	if(ans < inf){
		cout << ans << endl;
	}else{
		cout << -1 << endl;
	}

	return 0;
}
0