結果

問題 No.844 split game
ユーザー kenken714kenken714
提出日時 2019-06-28 22:44:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 1,922 bytes
コンパイル時間 798 ms
コンパイル使用メモリ 91,648 KB
実行使用メモリ 15,924 KB
最終ジャッジ日時 2023-09-14 22:27:20
合計ジャッジ時間 7,405 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
11,348 KB
testcase_01 AC 56 ms
10,376 KB
testcase_02 AC 181 ms
15,232 KB
testcase_03 AC 121 ms
13,108 KB
testcase_04 AC 61 ms
11,036 KB
testcase_05 AC 191 ms
15,008 KB
testcase_06 AC 53 ms
10,192 KB
testcase_07 AC 40 ms
9,896 KB
testcase_08 AC 26 ms
9,056 KB
testcase_09 AC 155 ms
14,160 KB
testcase_10 AC 207 ms
15,480 KB
testcase_11 AC 194 ms
14,952 KB
testcase_12 AC 149 ms
14,044 KB
testcase_13 AC 88 ms
11,392 KB
testcase_14 AC 77 ms
11,112 KB
testcase_15 AC 222 ms
15,740 KB
testcase_16 AC 213 ms
15,824 KB
testcase_17 AC 208 ms
15,924 KB
testcase_18 AC 211 ms
15,760 KB
testcase_19 AC 215 ms
15,924 KB
testcase_20 AC 211 ms
15,824 KB
testcase_21 AC 211 ms
15,876 KB
testcase_22 AC 213 ms
15,800 KB
testcase_23 AC 9 ms
8,552 KB
testcase_24 AC 16 ms
8,800 KB
testcase_25 AC 11 ms
8,560 KB
testcase_26 AC 7 ms
8,388 KB
testcase_27 AC 15 ms
8,764 KB
testcase_28 AC 5 ms
8,340 KB
testcase_29 AC 13 ms
8,768 KB
testcase_30 AC 15 ms
8,864 KB
testcase_31 AC 14 ms
8,692 KB
testcase_32 AC 6 ms
8,508 KB
testcase_33 AC 21 ms
9,052 KB
testcase_34 AC 13 ms
8,844 KB
testcase_35 AC 25 ms
9,312 KB
testcase_36 AC 16 ms
8,788 KB
testcase_37 AC 37 ms
9,596 KB
testcase_38 AC 66 ms
11,224 KB
testcase_39 AC 145 ms
14,460 KB
testcase_40 AC 37 ms
9,908 KB
testcase_41 AC 4 ms
8,284 KB
testcase_42 AC 5 ms
8,236 KB
testcase_43 AC 5 ms
8,360 KB
testcase_44 AC 4 ms
8,280 KB
testcase_45 AC 4 ms
8,296 KB
testcase_46 AC 4 ms
8,232 KB
testcase_47 AC 4 ms
8,240 KB
testcase_48 AC 4 ms
8,308 KB
testcase_49 AC 5 ms
8,240 KB
testcase_50 AC 4 ms
8,304 KB
testcase_51 AC 4 ms
8,240 KB
testcase_52 AC 4 ms
8,432 KB
testcase_53 AC 4 ms
8,404 KB
testcase_54 AC 4 ms
8,236 KB
testcase_55 AC 4 ms
8,244 KB
testcase_56 AC 4 ms
8,300 KB
testcase_57 AC 3 ms
8,344 KB
testcase_58 AC 4 ms
8,284 KB
testcase_59 AC 4 ms
8,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n, m, a, dp[110000], dp2[110000], ans = MINF;
map<P, ll> mp;
vector<P> s;

//セグ木
ll dat[510000], sz;

void init(ll n) {
	sz = 1;
	while (sz < n)sz *= 2;
	REP(i, sz * 2 - 1) dat[i] = MINF; //初期値
}

void update(ll k, ll a) { //場所(0-indexed), 値
	k += sz - 1;
	dat[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); //更新
	}
}

ll query(ll a, ll b, ll k, ll l, ll r) { //[a, b) 呼ぶとき (a, b, 0, 0, sz)
	if (r <= a or b <= l)return MINF;
	if (a <= l and r <= b)return dat[k];
	ll v1 = query(a, b, k * 2 + 1, l, (l + r) / 2);
	ll v2 = query(a, b, k * 2 + 2, (l + r) / 2, r);
	return max(v1, v2); //戻り値
}

int main() {
	init(110000);
	REPO(i, 101010)dp[i] = MINF;
	update(0, 0);
	cin >> n >> m >> a;
	REP(i, m) {
		ll l, r, p;
		cin >> l >> r >> p;
		s.push_back(P(r, l));
		mp[P(r, l)] = p;
	}
	sort(ALL(s));
	REP(i, m) {
		ll l = s[i].second, r = s[i].first;
		ll now = dp[l - 1] + mp[P(r, l)] - a;
		if (l != 1) now = max(now, query(0, l - 1, 0, 0, sz) + mp[P(r, l)] - a * 2);
		//cout << now << " " << query(0, l - 1, 0, 0, sz) + mp[P(r, l)] << endl;
		if (r == n) now += a;
		dp[r] = max(dp[r], now);
		update(r, dp[r]);
	}
	REP(i, 110000) {
		ans = max(ans, dp[i]);
		//cout << dp[i] << " " << i << endl;
	}
	cout << ans << endl;
}
0