結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 0 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 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 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 0 ms
4,348 KB
testcase_16 AC 1 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 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 65 ms
10,232 KB
testcase_29 AC 65 ms
10,232 KB
testcase_30 AC 65 ms
11,908 KB
testcase_31 AC 66 ms
11,908 KB
testcase_32 AC 35 ms
10,232 KB
testcase_33 AC 16 ms
7,064 KB
testcase_34 AC 25 ms
9,892 KB
testcase_35 AC 60 ms
11,908 KB
testcase_36 AC 33 ms
10,232 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:55:9: warning: ignoring return value of ‘ssize_t read(int, void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     read(STDIN_FILENO, buf, sizeof(buf));
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

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

bool cmpb(struct P x, struct P y) {
    return x.b < y.b;
}

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;
}

char buf[200000 * 33 + 100];
int k = 0;

int i32() {
    int res = 0;
    while (buf[k] < '0') k++;
    while (buf[k] >= '0') {
        res = res * 10 + (buf[k] - '0');
        k++;
    }
    return res;
}

int main() {
    read(STDIN_FILENO, buf, sizeof(buf));
    int n = i32();
    for (int i = 0; i < n; i++) {
        a[i].a = i32();
        a[i].b = i32();
        a[i].c = i32();
    }
    std::sort(a, a + n, 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;
        }
    }
    std::sort(a, a + n, 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