結果

問題 No.1826 Fruits Collecting
ユーザー se1ka2se1ka2
提出日時 2022-01-28 22:58:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,486 bytes
コンパイル時間 1,244 ms
コンパイル使用メモリ 92,888 KB
実行使用メモリ 50,560 KB
最終ジャッジ日時 2023-08-28 21:36:46
合計ジャッジ時間 32,098 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
14,528 KB
testcase_01 AC 10 ms
14,348 KB
testcase_02 AC 10 ms
14,424 KB
testcase_03 AC 14 ms
14,464 KB
testcase_04 AC 7 ms
14,232 KB
testcase_05 AC 745 ms
29,776 KB
testcase_06 AC 1,396 ms
41,284 KB
testcase_07 AC 925 ms
31,564 KB
testcase_08 AC 71 ms
15,908 KB
testcase_09 AC 1,362 ms
37,080 KB
testcase_10 AC 871 ms
30,960 KB
testcase_11 AC 832 ms
30,400 KB
testcase_12 AC 283 ms
20,864 KB
testcase_13 AC 126 ms
17,324 KB
testcase_14 AC 216 ms
18,944 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 5 ms
14,120 KB
testcase_26 AC 5 ms
14,144 KB
testcase_27 AC 6 ms
14,176 KB
testcase_28 AC 5 ms
14,412 KB
testcase_29 AC 6 ms
14,136 KB
testcase_30 AC 369 ms
22,140 KB
testcase_31 AC 814 ms
30,828 KB
testcase_32 AC 349 ms
22,232 KB
testcase_33 AC 1,455 ms
41,912 KB
testcase_34 AC 1,179 ms
35,048 KB
testcase_35 AC 216 ms
18,972 KB
testcase_36 AC 1,455 ms
41,460 KB
testcase_37 AC 607 ms
33,800 KB
testcase_38 AC 422 ms
29,184 KB
testcase_39 AC 607 ms
29,272 KB
testcase_40 AC 805 ms
31,616 KB
testcase_41 AC 151 ms
17,904 KB
testcase_42 AC 21 ms
14,936 KB
testcase_43 AC 6 ms
14,128 KB
testcase_44 AC 6 ms
14,420 KB
testcase_45 AC 6 ms
14,128 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 p[200005];

void divide_conquer(int a, int b){
    if(b - a <= 1) return;
    divide_conquer(a, (a + b) / 2);
	map<ll, int> mp;
	for(int i = a; i < b; i++) mp[l[i]]++;
	int m = b - a, k = 0;
	for(auto itr = mp.begin(); itr != mp.end(); itr++) mp[itr->first] = k++;
	for(int e = 0; e < m; e++){
		int i = a + e;
		p[e] = P(r[i], i);
	}
	sort(p, p + m);
	segtree<S, mx, e> seg(k);
	for(int e = 0; e < m; e++){
		int i = p[e].second;
		if(i < (a + b) / 2) seg.set(mp[l[i]], mx(seg.get(mp[l[i]]), S{dp[i]}));
		else dp[i] = max(dp[i], seg.prod(mp[l[i]], k).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