結果

問題 No.1826 Fruits Collecting
ユーザー se1ka2se1ka2
提出日時 2022-01-28 23:21:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 824 ms / 2,000 ms
コード長 1,576 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 85,972 KB
実行使用メモリ 29,580 KB
最終ジャッジ日時 2023-08-28 21:57:25
合計ジャッジ時間 17,946 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
16,372 KB
testcase_01 AC 9 ms
16,268 KB
testcase_02 AC 8 ms
16,300 KB
testcase_03 AC 11 ms
16,528 KB
testcase_04 AC 6 ms
16,224 KB
testcase_05 AC 309 ms
23,936 KB
testcase_06 AC 522 ms
28,360 KB
testcase_07 AC 358 ms
23,760 KB
testcase_08 AC 35 ms
16,732 KB
testcase_09 AC 504 ms
24,416 KB
testcase_10 AC 337 ms
23,692 KB
testcase_11 AC 326 ms
23,936 KB
testcase_12 AC 124 ms
20,700 KB
testcase_13 AC 61 ms
19,384 KB
testcase_14 AC 97 ms
19,524 KB
testcase_15 AC 818 ms
29,488 KB
testcase_16 AC 815 ms
29,324 KB
testcase_17 AC 818 ms
29,252 KB
testcase_18 AC 814 ms
29,268 KB
testcase_19 AC 818 ms
29,580 KB
testcase_20 AC 817 ms
29,336 KB
testcase_21 AC 824 ms
29,244 KB
testcase_22 AC 819 ms
29,340 KB
testcase_23 AC 817 ms
29,320 KB
testcase_24 AC 814 ms
29,324 KB
testcase_25 AC 5 ms
16,344 KB
testcase_26 AC 5 ms
16,464 KB
testcase_27 AC 6 ms
16,236 KB
testcase_28 AC 5 ms
16,184 KB
testcase_29 AC 6 ms
16,180 KB
testcase_30 AC 161 ms
20,720 KB
testcase_31 AC 332 ms
23,788 KB
testcase_32 AC 152 ms
20,932 KB
testcase_33 AC 540 ms
28,380 KB
testcase_34 AC 446 ms
24,280 KB
testcase_35 AC 96 ms
19,564 KB
testcase_36 AC 528 ms
28,476 KB
testcase_37 AC 226 ms
24,312 KB
testcase_38 AC 164 ms
23,844 KB
testcase_39 AC 340 ms
28,296 KB
testcase_40 AC 445 ms
29,036 KB
testcase_41 AC 92 ms
20,728 KB
testcase_42 AC 16 ms
16,464 KB
testcase_43 AC 5 ms
16,332 KB
testcase_44 AC 5 ms
16,372 KB
testcase_45 AC 5 ms
16,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/segtree>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll INF = 1000000000000000;

struct S{
    ll x;
};

S mx(S a, S b){
    return S{max(a.x, b.x)};
}

S e(){
    return S{-INF};
}

ll l[200005], r[200005];
ll v[200005];
ll dp[200005];
P pl[200005], pr[200005];
int re[200005];

void divide_conquer(int a, int b){
	if(b - a <= 1){
		for(int i = a; i < b; i++){
			for(int j = a; j < i; j++){
				if(l[i] <= l[j] && r[i] >= r[j]) dp[i] = max(dp[i], dp[j] + v[i]);
			}
		}
		return;
	}
    divide_conquer(a, (a + b) / 2);
	int m = b - a;
	for(int i = a; i < b; i++){
		pl[i - a] = P(l[i], -i);
		pr[i - a] = P(r[i], i);
	}
	sort(pl, pl + m);
	sort(pr, pr + m);
	for(int i = 0; i < m; i++) re[-pl[i].second] = i;
	segtree<S, mx, e> seg(m);
	for(int e = 0; e < m; e++){
		int i = pr[e].second;
		if(i < (a + b) / 2) seg.set(re[i], S{dp[i]});
		else dp[i] = max(dp[i], seg.prod(re[i], m).x + v[i]);
	}
    divide_conquer((a + b) / 2, b);
}

int main()
{
    int n;
	cin >> n;
	PP q[200005];
	q[0] = PP(P(0, 0), 0);
	for(int i = 1; i <= n; i++){
		ll t, x, v;
		cin >> t >> x >> v;
		q[i] = PP(P(t, x), v);
	}
	sort(q, q + n + 1);
	for(int i = 0; i <= n; i++){
		v[i] = q[i].second;
		l[i] = q[i].first.second - q[i].first.first;
		r[i] = q[i].first.second + q[i].first.first;
		dp[i] = -INF;
	}
	dp[0] = 0;
	divide_conquer(0, n + 1);
	ll ans = 0;
	for(int i = 1; i <= n; i++) ans = max(ans, dp[i]);
    cout << ans << endl;
}
0