結果

問題 No.844 split game
ユーザー Yang33Yang33
提出日時 2019-07-05 14:41:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 2,290 ms
コンパイル使用メモリ 176,668 KB
実行使用メモリ 13,080 KB
最終ジャッジ日時 2023-10-21 17:05:05
合計ジャッジ時間 8,041 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
6,744 KB
testcase_01 AC 41 ms
11,496 KB
testcase_02 AC 92 ms
7,800 KB
testcase_03 AC 73 ms
10,704 KB
testcase_04 AC 36 ms
6,480 KB
testcase_05 AC 113 ms
11,232 KB
testcase_06 AC 35 ms
6,744 KB
testcase_07 AC 34 ms
9,912 KB
testcase_08 AC 18 ms
5,688 KB
testcase_09 AC 78 ms
5,424 KB
testcase_10 AC 117 ms
9,912 KB
testcase_11 AC 118 ms
12,552 KB
testcase_12 AC 76 ms
5,160 KB
testcase_13 AC 47 ms
4,896 KB
testcase_14 AC 52 ms
9,120 KB
testcase_15 AC 126 ms
13,080 KB
testcase_16 AC 125 ms
13,080 KB
testcase_17 AC 125 ms
13,080 KB
testcase_18 AC 126 ms
13,080 KB
testcase_19 AC 129 ms
13,080 KB
testcase_20 AC 125 ms
13,080 KB
testcase_21 AC 125 ms
13,080 KB
testcase_22 AC 125 ms
13,080 KB
testcase_23 AC 5 ms
4,348 KB
testcase_24 AC 9 ms
4,368 KB
testcase_25 AC 6 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 8 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 8 ms
4,368 KB
testcase_30 AC 10 ms
4,348 KB
testcase_31 AC 8 ms
4,348 KB
testcase_32 AC 4 ms
4,348 KB
testcase_33 AC 10 ms
4,348 KB
testcase_34 AC 6 ms
4,348 KB
testcase_35 AC 12 ms
4,348 KB
testcase_36 AC 8 ms
4,348 KB
testcase_37 AC 17 ms
4,348 KB
testcase_38 AC 32 ms
4,456 KB
testcase_39 AC 69 ms
5,688 KB
testcase_40 AC 26 ms
8,064 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 1 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 1 ms
4,348 KB
testcase_52 AC 1 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s; i < t; i++)
using LL = long long;
using VL = vector<LL>;

int main() {

	int N, M, A; cin >> N >> M >> A;
	using PII = pair<int, int>;
	vector<vector<PII>>seg(N + 1);
	FOR(i, 0, M) {
		int L, R, V; cin >> L >> R >> V;
		seg[R].emplace_back(L, V);
	}
	const int USED = 1;
	const int SETED = 0;
	const LL LINF = 1e18;
	vector<VL> dp(N + 1, VL(2, -LINF));
	auto setmax = [](LL &a, LL b) {a = max(a, b); };
	dp[0][SETED] = 0;
	LL allmax = 0;
	FOR(R, 1, N + 1) {
		for (auto it : seg[R]) {
			int L = it.first; LL v = it.second + (R == N ? 0 : -A);
			setmax(dp[R][USED], dp[L - 1][SETED] + v);
		}
		setmax(dp[R][SETED], allmax - A);
		setmax(dp[R][SETED], dp[R][USED]);

		setmax(allmax, dp[R][SETED]);
		setmax(allmax, dp[R][USED]);
	}

	LL ans = 0;
	FOR(i, 0, N + 1) {
		setmax(ans, dp[i][USED]);
		setmax(ans, dp[i][SETED]);
	}
	cout << ans << endl;
}
0