結果

問題 No.1037 exhausted
ユーザー QCFiumQCFium
提出日時 2020-04-24 22:09:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 982 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 165,088 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-05 05:08:08
合計ジャッジ時間 2,656 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int max = ri();
	int l = ri();
	struct Station {
		int pos;
		int max;
		int cost;
	};
	Station stations[n];
	for (auto &i : stations) i.pos = ri(), i.max = ri(), i.cost = ri();
	int64_t dp[max + 1];
	for (auto &i : dp) i = 1000000000000000000;
	dp[max] = 0;
	int last = 0;
	for (int i = 0; i < n; i++) {
		int move = stations[i].pos - last;
		last = stations[i].pos;
		for (int j = 0; j < move && j <= max; j++) dp[j] = 1000000000000000000;
		if (move) for (int j = move; j <= max; j++) dp[j - move] = dp[j], dp[j] = 1000000000000000000;
		for (int j = max; j >= 0; j--) {
			auto &target = dp[std::min(j + stations[i].max, max)];
			target = std::min(target, dp[j] + stations[i].cost);
		}
	}
	int64_t res = 1000000000000000000;
	for (int i = l - last; i <= max; i++) res = std::min(res, dp[i]);
	printf("%" PRId64 "\n", res == 1000000000000000000 ? -1 : res);
	return 0;
}
0