結果

問題 No.1037 exhausted
ユーザー yuruhiyayuruhiya
提出日時 2020-04-29 19:40:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 2,675 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 60,848 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 20:15:05
合計ジャッジ時間 1,981 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#pragma GCC optimize ("Ofast")
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rfor(i, m, n) for (int i = (m); i >= (n); --i)
using ll = long long;

#ifdef _WIN32
#define gc _getchar_nolock
#define pc _putchar_nolock
#else
#define gc getchar_unlocked
#define pc putchar_unlocked
#endif
#if __has_include("dump.hpp")
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

inline void inui(int& v)noexcept {
	v = 0;
	for (char c = gc(); isdigit(c); c = gc())
		v = v * 10 + (c - '0');
}
inline void inul(ll& v)noexcept {
	v = 0;
	for (char c = gc(); isdigit(c); c = gc())
		v = v * 10 + (c - '0');
}
inline void ini(int& v)noexcept {
	v = 0; char c = gc();
	bool f = false;
	if (c == '-') { f = true; c = gc(); }
	for (; isdigit(c); c = gc())
		v = v * 10 + (c - '0');
	if (f)v = -v;
}
inline void inl(ll& v)noexcept {
	v = 0; char c = gc();
	bool f = false;
	if (c == '-') { f = true; c = gc(); }
	for (; isdigit(c); c = gc())
		v = v * 10 + (c - '0');
	if (f)v = -v;
}
inline void ins(char* c, int n)noexcept {
	while (n--) { *c = gc(); ++c; }
}
inline void outi(int v)noexcept {
	if (v < 0)pc('-'), v = -v;
	char b[10]; int n = 0;
	while (v)b[n++] = '0' + v % 10, v /= 10;
	if (!n)b[n++] = '0';
	while (n--)pc(b[n]);
}
inline void outui(int v)noexcept {
	char b[10]; int n = 0;
	while (v)b[n++] = '0' + v % 10, v /= 10;
	if (!n)b[n++] = '0';
	while (n--)pc(b[n]);
}
inline void outl(ll v)noexcept {
	if (v < 0)pc('-'), v = -v;
	char b[20]; int n = 0;
	while (v)b[n++] = '0' + v % 10, v /= 10;
	if (!n)b[n++] = '0';
	while (n--)pc(b[n]);
}
inline void outul(ll v)noexcept {
	char b[20]; int n = 0;
	while (v)b[n++] = '0' + v % 10, v /= 10;
	if (!n)b[n++] = '0';
	while (n--)pc(b[n]);
}

constexpr int MAX_N = 2005, MAX_V = 2005;
constexpr ll inf = 1e16;
int N, V, L;
int x[MAX_N], v[MAX_N];
ll w[MAX_N];

int main() {
	inui(N); inui(V); inui(L);
	rep(i, N) {
		inui(x[i + 1]);
		inui(v[i + 1]);
		inul(w[i + 1]);
	}
	x[N + 1] = L;
	N += 2;
	
	vector<ll> dp(V + 1, inf);
	dp[V] = 0;
	FOR(i, 1, N) {
		int dist = x[i] - x[i - 1];
		if (dist > V) {
			puts("-1");
			return 0;
		}
		fill(dp.begin(), dp.begin() + dist, inf);
		rotate(dp.begin(), dp.begin() + dist, dp.end());
		rrep(j, V) {
			int k = min(V, j + v[i]);
			dp[k] = min(dp[k], dp[j] + w[i]);
		}
	}

	ll ans = *min_element(dp.begin(), dp.end());
	if (ans != inf) {
		outul(ans);
		pc('\n');
	} else {
		puts("-1");
	}
}
0