結果

問題 No.777 再帰的ケーキ
ユーザー pekempeypekempey
提出日時 2018-12-24 18:55:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 2,008 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 39,020 KB
実行使用メモリ 15,884 KB
最終ジャッジ日時 2023-10-26 03:03:14
合計ジャッジ時間 1,986 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
14,160 KB
testcase_01 AC 3 ms
14,160 KB
testcase_02 AC 2 ms
14,160 KB
testcase_03 AC 2 ms
14,160 KB
testcase_04 AC 2 ms
14,160 KB
testcase_05 AC 2 ms
14,160 KB
testcase_06 AC 2 ms
14,160 KB
testcase_07 AC 3 ms
14,160 KB
testcase_08 AC 3 ms
14,160 KB
testcase_09 AC 3 ms
14,160 KB
testcase_10 AC 3 ms
14,160 KB
testcase_11 AC 3 ms
14,160 KB
testcase_12 AC 3 ms
14,160 KB
testcase_13 AC 3 ms
14,160 KB
testcase_14 AC 2 ms
14,160 KB
testcase_15 AC 2 ms
14,160 KB
testcase_16 AC 2 ms
14,160 KB
testcase_17 AC 2 ms
14,160 KB
testcase_18 AC 3 ms
14,160 KB
testcase_19 AC 2 ms
14,160 KB
testcase_20 AC 2 ms
14,160 KB
testcase_21 AC 3 ms
14,164 KB
testcase_22 AC 3 ms
14,164 KB
testcase_23 AC 3 ms
14,160 KB
testcase_24 AC 3 ms
14,160 KB
testcase_25 AC 2 ms
14,164 KB
testcase_26 AC 3 ms
14,164 KB
testcase_27 AC 3 ms
14,160 KB
testcase_28 AC 31 ms
15,884 KB
testcase_29 AC 30 ms
15,884 KB
testcase_30 AC 35 ms
15,884 KB
testcase_31 AC 35 ms
15,884 KB
testcase_32 AC 24 ms
15,884 KB
testcase_33 AC 11 ms
14,472 KB
testcase_34 AC 16 ms
15,248 KB
testcase_35 AC 30 ms
15,884 KB
testcase_36 AC 23 ms
15,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <unistd.h>
#include <fcntl.h>

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

int n;
struct P a[200000];
long long bit[200001];

long long max(long long x, long long y) {
    return x > y ? x : y;
}

void update(int k, long long v) {
    for (int i = k + 1; i <= 200000 && bit[i] < v; i += i & -i) {
        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;
}

template<int N, class T, class F>
void counting_sort(T *a, int n, F f) {
    static int c[N + 1];
    static T t[200000];
    for (int i = 0; i <= N; i++) {
        c[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        c[f(a[i]) + 1]++;
        t[i] = a[i];
    }
    for (int i = 0; i < N; i++) {
        c[i + 1] += c[i];
    }
    for (int i = 0; i < n; i++) {
        a[c[f(t[i])]++] = t[i];
    }
}

int i32() {
    int n, c;
    while ((c = getchar_unlocked()) < '0');
    n = c - '0';
    while ((c = getchar_unlocked()) >= '0') {
        n = n * 10 + (c - '0');
    }
    return n;
}

int main() {
    int n = i32();
    for (int i = 0; i < n; i++) {
        a[i].a = i32();
        a[i].b = i32();
        a[i].c = i32();
    }
    counting_sort<65536>(a, n, [](struct P x) { return x.b & 0xffff; });
    counting_sort<65536>(a, n, [](struct P x) { return x.b >> 16 & 0xffff; });
    {
        int k = -1;
        int p = -1;
        for (int i = 0; i < n; i++) {
            k += p != a[i].b;
            p = a[i].b;
            a[i].b = k;
        }
    }
    for (int i = 0; i < n / 2; i++) {
        struct P t = a[i];
        a[i] = a[n - 1 - i];
        a[n - 1 - i] = t;
    }
    counting_sort<65536>(a, n, [](struct P x) { return x.a & 0xffff; });
    counting_sort<65536>(a, n, [](struct P x) { return x.a >> 16 & 0xffff; });
    for (int i = 0; i < n; i++) {
        update(a[i].b, query(a[i].b) + a[i].c);
    }
    printf("%lld\n", query(200000));
}


0