結果

問題 No.1826 Fruits Collecting
ユーザー se1ka2se1ka2
提出日時 2022-01-28 23:14:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,577 bytes
コンパイル時間 1,017 ms
コンパイル使用メモリ 86,044 KB
実行使用メモリ 29,440 KB
最終ジャッジ日時 2023-08-28 21:50:36
合計ジャッジ時間 17,533 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
16,204 KB
testcase_01 AC 7 ms
16,276 KB
testcase_02 AC 8 ms
16,296 KB
testcase_03 AC 10 ms
16,328 KB
testcase_04 AC 6 ms
16,256 KB
testcase_05 AC 292 ms
23,804 KB
testcase_06 AC 502 ms
28,344 KB
testcase_07 AC 345 ms
23,920 KB
testcase_08 AC 36 ms
16,688 KB
testcase_09 AC 482 ms
24,376 KB
testcase_10 AC 323 ms
23,800 KB
testcase_11 AC 315 ms
24,028 KB
testcase_12 AC 120 ms
20,952 KB
testcase_13 AC 57 ms
19,436 KB
testcase_14 AC 93 ms
19,464 KB
testcase_15 AC 789 ms
29,440 KB
testcase_16 AC 801 ms
29,376 KB
testcase_17 AC 788 ms
29,412 KB
testcase_18 AC 788 ms
29,316 KB
testcase_19 AC 788 ms
29,240 KB
testcase_20 AC 786 ms
29,356 KB
testcase_21 AC 788 ms
29,392 KB
testcase_22 AC 783 ms
29,376 KB
testcase_23 AC 785 ms
29,428 KB
testcase_24 AC 785 ms
29,304 KB
testcase_25 AC 5 ms
16,172 KB
testcase_26 AC 5 ms
16,164 KB
testcase_27 AC 6 ms
16,464 KB
testcase_28 AC 5 ms
16,208 KB
testcase_29 AC 5 ms
16,168 KB
testcase_30 AC 154 ms
20,692 KB
testcase_31 AC 317 ms
23,632 KB
testcase_32 AC 147 ms
21,100 KB
testcase_33 AC 523 ms
28,468 KB
testcase_34 AC 432 ms
24,224 KB
testcase_35 AC 94 ms
19,468 KB
testcase_36 AC 511 ms
28,388 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 5 ms
16,172 KB
testcase_45 AC 6 ms
16,220 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