結果

問題 No.1037 exhausted
ユーザー 👑 jupirojupiro
提出日時 2020-04-24 21:55:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,845 bytes
コンパイル時間 1,236 ms
コンパイル使用メモリ 133,240 KB
実行使用メモリ 35,072 KB
最終ジャッジ日時 2024-04-23 03:13:43
合計ジャッジ時間 2,271 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>

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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;



int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll N, V, L; scanf("%lld %lld %lld", &N, &V, &L);
	vector<vector<ll>> dp(N + 1, vector<ll>(V + 1, INF));
	dp[0][V] = 0;
	vector<ll> x(N), v(N), w(N);
	for (int i = 0; i < N; i++) scanf("%lld %lld %lld", &x[i], &v[i], &w[i]);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= V; j++) {
			if (dp[i][j] == INF) continue;
			if (i == 0) {
				if (x[i] > j) continue;
				chmin(dp[i + 1][j - x[i]], dp[i][j]);
				chmin(dp[i + 1][min(V, j - x[i] + v[i])], dp[i][j] + w[i]);
			}
			else {
				if (x[i] - x[i - 1]> j) continue;
				chmin(dp[i + 1][j - x[i] + x[i -1]], dp[i][j]);
				chmin(dp[i + 1][min(V, j - x[i] + x[i - 1] + v[i])], dp[i][j] + w[i]);
			}
		}
	}
	ll res = INF;
	for (int j = 0; j <= V; j++) {
		ll len = L - x.back();
		if (len > j) continue;
		chmin(res, dp[N][j]);
	}
	if (res == INF) puts("-1");
	else cout << res << endl;
	return 0;
}


0