結果

問題 No.777 再帰的ケーキ
ユーザー pekempeypekempey
提出日時 2018-12-24 10:17:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 995 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 71,856 KB
実行使用メモリ 7,880 KB
最終ジャッジ日時 2023-10-26 02:57:42
合計ジャッジ時間 4,812 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 4 ms
4,348 KB
testcase_26 AC 5 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 263 ms
7,876 KB
testcase_29 AC 262 ms
7,872 KB
testcase_30 AC 309 ms
7,872 KB
testcase_31 AC 308 ms
7,872 KB
testcase_32 AC 229 ms
7,880 KB
testcase_33 AC 119 ms
5,196 KB
testcase_34 AC 179 ms
6,252 KB
testcase_35 AC 297 ms
7,084 KB
testcase_36 AC 228 ms
7,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct P {
    int a, b, c;
};

bool operator<(P x, P y) {
    if (x.a != y.a) return x.a < y.a;
    return x.b > y.b;
}

long long bit[200001];

void update(int k, long long v) {
    for (int i = k + 1; i <= 200000; i += i & -i) {
        bit[i] = max(bit[i], v);
    }
}

long long query(int k) {
    long long res = 0;
    for (int i = k; i > 0; i -= i & -i) {
        res = max(res, bit[i]);
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    vector<P> a(n);
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].a >> a[i].b >> a[i].c;
        d[i] = a[i].b;
    }
    sort(a.begin(), a.end());
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    for (int i = 0; i < n; i++) {
        a[i].b = lower_bound(d.begin(), d.end(), a[i].b) - d.begin();
        update(a[i].b, query(a[i].b) + a[i].c);
    }
    cout << query(200000) << endl;
}

0