結果

問題 No.1037 exhausted
ユーザー oteraotera
提出日時 2020-06-24 10:36:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 2,319 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 111,920 KB
実行使用メモリ 35,604 KB
最終ジャッジ日時 2023-09-16 20:56:32
合計ジャッジ時間 2,450 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
35,264 KB
testcase_01 AC 11 ms
35,244 KB
testcase_02 AC 11 ms
35,220 KB
testcase_03 AC 11 ms
35,256 KB
testcase_04 AC 11 ms
35,532 KB
testcase_05 AC 11 ms
35,260 KB
testcase_06 AC 11 ms
35,204 KB
testcase_07 AC 11 ms
35,288 KB
testcase_08 AC 11 ms
35,212 KB
testcase_09 AC 11 ms
35,216 KB
testcase_10 AC 11 ms
35,228 KB
testcase_11 AC 11 ms
35,336 KB
testcase_12 AC 22 ms
35,552 KB
testcase_13 AC 22 ms
35,556 KB
testcase_14 AC 22 ms
35,272 KB
testcase_15 AC 22 ms
35,264 KB
testcase_16 AC 22 ms
35,344 KB
testcase_17 AC 23 ms
35,464 KB
testcase_18 AC 22 ms
35,268 KB
testcase_19 AC 22 ms
35,604 KB
testcase_20 AC 21 ms
35,272 KB
testcase_21 AC 20 ms
35,276 KB
testcase_22 AC 18 ms
35,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n, V, L; cin >> n >> V >> L;
    vector<int> x(n + 2), v(n + 2), w(n + 2);
	x[0] = 0, x[n + 1] = L;
    rep(i, n) {
        cin >> x[i + 1] >> v[i + 1] >> w[i + 1];
    }
    static int dp[2020][2020];
	rep(i, 2020) {
		rep(j, 2020) {
			dp[i][j] = INF;
		}
	}
	dp[0][V] = 0;
	for(int i = 1; i <= n; ++ i) {
		for(int j = 0; j <= V; ++ j) {
			if(j - (x[i] - x[i - 1]) < 0) continue;
			chmin(dp[i][j - (x[i] - x[i - 1])], dp[i - 1][j]);
			int res = min(V, j - (x[i] - x[i - 1]) + v[i]);
			chmin(dp[i][res], dp[i - 1][j] + w[i]);
		}
	}
	int ans = INF;
	for(int j = 0; j <= V; ++ j) {
		if(j - (x[n + 1] - x[n]) >= 0) chmin(ans, dp[n][j]);
	}
	cout << (ans == INF ? -1 : ans) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	//GCJ
	// int t; cin >> t;
	// rep(i, t) {
	// 	cout << "Case #" << i + 1 << ": ";
	// 	solve();
	// }
	solve();
    return 0;
}
0