結果

問題 No.844 split game
ユーザー gazellegazelle
提出日時 2019-06-28 23:03:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 2,522 bytes
コンパイル時間 2,164 ms
コンパイル使用メモリ 208,016 KB
実行使用メモリ 13,644 KB
最終ジャッジ日時 2023-09-14 22:34:13
合計ジャッジ時間 5,744 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
6,720 KB
testcase_01 AC 25 ms
11,152 KB
testcase_02 AC 43 ms
8,240 KB
testcase_03 AC 38 ms
10,952 KB
testcase_04 AC 18 ms
6,464 KB
testcase_05 AC 51 ms
11,480 KB
testcase_06 AC 17 ms
6,704 KB
testcase_07 AC 20 ms
9,572 KB
testcase_08 AC 10 ms
5,340 KB
testcase_09 AC 31 ms
5,864 KB
testcase_10 AC 53 ms
10,472 KB
testcase_11 AC 55 ms
13,184 KB
testcase_12 AC 30 ms
5,600 KB
testcase_13 AC 18 ms
5,160 KB
testcase_14 AC 26 ms
9,100 KB
testcase_15 AC 60 ms
13,572 KB
testcase_16 AC 60 ms
13,612 KB
testcase_17 AC 61 ms
13,272 KB
testcase_18 AC 61 ms
13,272 KB
testcase_19 AC 61 ms
13,644 KB
testcase_20 AC 60 ms
13,472 KB
testcase_21 AC 61 ms
13,268 KB
testcase_22 AC 62 ms
13,472 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 5 ms
4,380 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 7 ms
4,376 KB
testcase_38 AC 14 ms
4,672 KB
testcase_39 AC 30 ms
6,428 KB
testcase_40 AC 15 ms
7,836 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,500 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define FOR(i, n, m) for(long long i = n; i < (int)m; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = std::int_fast64_t;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 1000000007;
constexpr long double eps = 1e-15;
template<typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> p) {
	os << to_string(p.first) << " " << to_string(p.second);
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	REP(i, v.size()) {
		if(i) os << " ";
		os << to_string(v[i]);
	}
	return os;
}

/*
template<typename T>
struct Treap {
	double drand() { // random number in [0, 1]
		static random_device rd;
		static mt19937 mt(rd());
		return (unsigned)mt() / (double)numeric_limits<unsigned>::max();
	}
	T v;
	double p;
	int cnt;
	Treap* lch;
	Treap* rch;
	Treap(T v) : v(v), p(drand()), cnt(1), lch(NULL), rch(NULL) { }
	Treap* update() {
		this->size = size(this->lch) + size(this->rch) + 1;
		return this;
	}
	static int size(Treap* t) {
		if(!t) return 0;
		else return t->cnt;
	}
	static Treap* merge(Treap* l, Treap* r) {
		if(!l || !r) {
			if(!l) return r;
			else return l;
		}
		if(l->p >= r->p) {
			l->rch = merge(l->rch, r);
			return l->update();
		} else {
			r->lch = merge(r->lch, l);
			return r->update();
		}
	}
	static pair<Treap*, Treap*> split(Treap* t, int k) {
		// split [0, k) and [k, n)
		if(k == 0) return {NULL, t};
		if(!(t->l)) {
			auto tmp = split(t->r, k - 1);
			t->r = tmp.first;
			return {t->update(), tmp.second};
		} else if(!(t->r)) {
			auto tmp = split(t->r, k - 1);
			t->r = tmp.first;
			return {t->update(), tmp.second};
		} else {

		}
	}
	Treap* insert() {
	}
	Treap* erase() {
	}
	T operator[](int k) {
	}
};
*/

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m, a;
	cin >> n >> m >> a;
	vector<vector<P>> seg(n + 1);
	REP(i, m) {
		ll l, r, p;
		cin >> l >> r >> p;
		l--;
		seg[r].pb(P(l, p));
	}
	vector<vector<ll>> dp(n + 1, vector<ll>(2, -inf*inf));
	dp[0][1] = 0;
	FOR(i, 1, n + 1) {
		dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
		if(i != n) dp[i][1] = -a;
		else dp[i][1] = 0;
		ll d = 0;
		for(auto p: seg[i]) {
			if(p.first == i) dp[i][1] += p.second;
			else {
				d = max({d, dp[p.first][0] - a + p.second, dp[p.first][1] + p.second});
			}
		}
		dp[i][1] += d;
	}
	cout << max(dp[n][0], dp[n][1]) << endl;
	return 0;
}
// ---------------------------------------
0