結果

問題 No.1826 Fruits Collecting
ユーザー milanis48663220milanis48663220
提出日時 2022-01-28 23:01:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 2,523 bytes
コンパイル時間 1,495 ms
コンパイル使用メモリ 135,504 KB
実行使用メモリ 27,716 KB
最終ジャッジ日時 2023-08-28 21:38:50
合計ジャッジ時間 9,573 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 93 ms
12,656 KB
testcase_06 AC 170 ms
19,452 KB
testcase_07 AC 108 ms
13,760 KB
testcase_08 AC 11 ms
4,692 KB
testcase_09 AC 159 ms
16,460 KB
testcase_10 AC 104 ms
13,364 KB
testcase_11 AC 97 ms
13,116 KB
testcase_12 AC 37 ms
7,280 KB
testcase_13 AC 18 ms
5,012 KB
testcase_14 AC 29 ms
6,212 KB
testcase_15 AC 303 ms
26,420 KB
testcase_16 AC 284 ms
26,256 KB
testcase_17 AC 280 ms
24,416 KB
testcase_18 AC 305 ms
27,632 KB
testcase_19 AC 285 ms
26,328 KB
testcase_20 AC 296 ms
26,552 KB
testcase_21 AC 285 ms
26,416 KB
testcase_22 AC 283 ms
27,128 KB
testcase_23 AC 283 ms
26,532 KB
testcase_24 AC 289 ms
27,716 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 49 ms
8,172 KB
testcase_31 AC 105 ms
13,024 KB
testcase_32 AC 48 ms
7,916 KB
testcase_33 AC 182 ms
19,916 KB
testcase_34 AC 163 ms
14,932 KB
testcase_35 AC 30 ms
5,980 KB
testcase_36 AC 178 ms
19,624 KB
testcase_37 AC 116 ms
15,352 KB
testcase_38 AC 75 ms
12,148 KB
testcase_39 AC 100 ms
13,020 KB
testcase_40 AC 129 ms
15,552 KB
testcase_41 AC 27 ms
5,684 KB
testcase_42 AC 4 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/segtree>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

template<typename T>
class Compress{
    public:
    vector<T> data;
    int offset;
    Compress(vector<T> data_, int offset=0): offset(offset){
        set<T> st;
        for(T x: data_) st.insert(x);
        for(T x: st) data.push_back(x);
    };
    int operator[](T x) {
        auto p = lower_bound(data.begin(), data.end(), x);
        assert(x == *p);
        return offset+(p-data.begin());
	}
    T inv(int x){
        return data[x-offset];
    }
    int size(){
        return data.size();
    }
};

using T = tuple<ll, ll, ll>;
const ll inf = 1e18;

ll e(){
    return -inf;
}

ll op(ll x, ll y){
    return max(x, y);
}

using Seg = atcoder::segtree<ll, op, e>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<T> vt(n);
    vector<ll> vv = {-inf, 0, inf};
    for(int i = 0; i < n; i++){
        ll t, x, v; cin >> t >> x >> v;
        vt[i] = T(x+t, -(x-t), v);
        vv.push_back(x-t);
    }
    sort(vt.begin(), vt.end());
    auto cp = Compress<ll>(vv);
    int m = cp.size();
    Seg dp(m);
    dp.set(cp[0], 0);
    for(auto [X, _Y, v]: vt){
        if(X < 0) continue;
        ll Y = -_Y;
        int l = cp[Y];
        ll mx = dp.prod(l, m);
        dp.set(l, mx+v);
    }
    cout << dp.all_prod() << endl;
}
0