結果

問題 No.777 再帰的ケーキ
ユーザー pekempeypekempey
提出日時 2018-12-24 10:38:46
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,344 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 30,752 KB
実行使用メモリ 8,176 KB
最終ジャッジ日時 2023-10-26 02:58:01
合計ジャッジ時間 2,938 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 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 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 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 2 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 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 156 ms
8,176 KB
testcase_29 AC 155 ms
8,176 KB
testcase_30 AC 164 ms
8,176 KB
testcase_31 AC 165 ms
8,176 KB
testcase_32 AC 96 ms
7,008 KB
testcase_33 AC 59 ms
5,200 KB
testcase_34 AC 88 ms
6,372 KB
testcase_35 AC 145 ms
8,176 KB
testcase_36 AC 97 ms
7,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.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;
}

int cmp(const void *x_, const void *y_) {
    struct P x = *(struct P *)x_;
    struct P y = *(struct P *)y_;
    if (x.a != y.a) return x.a - y.a;
    return y.b - x.b;
}

int cmpb(const void *x_, const void *y_) {
    struct P x = *(struct P *)x_;
    struct P y = *(struct P *)y_;
    return x.b - y.b;
}

void update(int k, long long v) {
    if (bit[k] < 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;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &a[i].a, &a[i].b, &a[i].c);
    }
    qsort(a, n, sizeof(struct P), cmpb);
    {
        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;
        }
    }
    qsort(a, n, sizeof(struct P), cmp);
    for (int i = 0; i < n; i++) {
        update(a[i].b, query(a[i].b) + a[i].c);
    }
    printf("%lld\n", query(200000));
}

0