結果

問題 No.1037 exhausted
ユーザー polylogKpolylogK
提出日時 2020-04-25 01:33:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,121 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 171,220 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-05 07:05:25
合計ジャッジ時間 3,070 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, v, l; scanf("%d%d%d", &n, &v, &l);
	std::vector<int> x(n + 1), y(n + 1);
	std::vector<i64> z(n + 1);
	for(int i = 1; i <= n; i++) scanf("%d%d%lld", &x[i], &y[i], &z[i]);
	x.push_back(l);
	y.push_back(0);
	z.push_back(0);

	std::vector<i64> dp(v + 1, 0);
	for(int i = 1; i < (int)x.size(); i++) {
		std::vector<i64> to(v + 1, 1LL << 60);

		int diff = x[i] - x[i  -1];
		for(int j = x[i] - x[i - 1]; j < v + 1; j++) {
			to[j - diff] = std::min(to[j - diff], dp[j]);
			if(j - diff + y[i] < v + 1) to[j - diff + y[i]] = std::min(to[j - diff + y[i]], dp[j] + z[i]);
		}
		dp.swap(to);
	}

	i64 ans = *std::min_element(begin(dp), end(dp));
	if(ans == 1LL << 60) ans = -1;
	printf("%lld\n", ans);
	return 0;
}
0