結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
14,160 KB
testcase_01 AC 9 ms
14,124 KB
testcase_02 AC 9 ms
14,412 KB
testcase_03 AC 15 ms
14,272 KB
testcase_04 AC 6 ms
14,160 KB
testcase_05 AC 297 ms
23,928 KB
testcase_06 AC 510 ms
28,332 KB
testcase_07 AC 347 ms
23,748 KB
testcase_08 AC 35 ms
16,612 KB
testcase_09 AC 488 ms
24,392 KB
testcase_10 AC 328 ms
23,840 KB
testcase_11 AC 317 ms
24,024 KB
testcase_12 AC 122 ms
20,808 KB
testcase_13 AC 59 ms
19,360 KB
testcase_14 AC 93 ms
19,464 KB
testcase_15 AC 799 ms
29,356 KB
testcase_16 AC 796 ms
29,244 KB
testcase_17 AC 795 ms
29,344 KB
testcase_18 AC 794 ms
29,416 KB
testcase_19 AC 794 ms
29,320 KB
testcase_20 AC 794 ms
29,432 KB
testcase_21 AC 791 ms
29,560 KB
testcase_22 AC 788 ms
29,296 KB
testcase_23 AC 790 ms
29,420 KB
testcase_24 AC 784 ms
29,240 KB
testcase_25 AC 5 ms
14,104 KB
testcase_26 AC 4 ms
14,136 KB
testcase_27 AC 5 ms
14,152 KB
testcase_28 AC 5 ms
14,384 KB
testcase_29 AC 5 ms
14,120 KB
testcase_30 AC 155 ms
20,728 KB
testcase_31 AC 320 ms
23,616 KB
testcase_32 AC 148 ms
20,964 KB
testcase_33 AC 527 ms
28,392 KB
testcase_34 AC 434 ms
24,296 KB
testcase_35 AC 95 ms
19,804 KB
testcase_36 AC 514 ms
28,308 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 6 ms
14,120 KB
testcase_44 AC 5 ms
14,120 KB
testcase_45 AC 5 ms
14,116 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;
	if(n <= 5000){
		for(int i = 1; i <= n; i++){
			for(int j = 0; j < i; j++){
				if(l[i] <= l[j] && r[i] >= r[j]) dp[i] = max(dp[i], dp[j] + v[i]);
			}
		}
	}
	else{
		divide_conquer(0, n + 1);
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++) ans = max(ans, dp[i]);
    cout << ans << endl;
}
0