結果

問題 No.777 再帰的ケーキ
ユーザー nanaenanae
提出日時 2018-12-29 13:37:07
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 2,051 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 114,844 KB
実行使用メモリ 25,804 KB
最終ジャッジ日時 2023-09-03 21:46:43
合計ジャッジ時間 4,959 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 320 ms
23,480 KB
testcase_29 AC 306 ms
23,672 KB
testcase_30 AC 324 ms
25,756 KB
testcase_31 AC 331 ms
25,804 KB
testcase_32 AC 194 ms
22,908 KB
testcase_33 AC 93 ms
7,304 KB
testcase_34 AC 138 ms
9,864 KB
testcase_35 AC 260 ms
13,144 KB
testcase_36 AC 192 ms
24,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

alias Cake = Tuple!(int, "a", int, "b", int, "c");

void main() {
    int n;
    scan(n);

    auto cs = new Cake[](n);

    foreach (i ; 0 .. n) {
        int a, b, c;
        scan(a, b, c);
        cs[i] = Cake(a, b, c);
    }

    int[int] zt;

    cs.sort!"a.b < b.b"();
    int rank = 1;
    zt[cs[0].b] = rank;

    foreach (i ; 1 .. n) {
        if (cs[i].b == cs[i-1].b) {
            continue;
        }
        rank++;
        zt[cs[i].b] = rank;
    }

    auto bit = FenwickTree!(long)(n + 10);

    cs.multiSort!("a.a < b.a", "a.b > b.b")();

    auto cur = new long[](n + 10);

    foreach (i ; 0 .. n) {
        auto res = bit.pmax(zt[cs[i].b]);
        res += cs[i].c;

        if (res > cur[zt[cs[i].b]]) {
            bit.update(zt[cs[i].b], res);
            cur[zt[cs[i].b]] = res;
        }
    }

    auto ans = bit.pmax(n + 10);

    writeln(ans);
}


struct FenwickTree(T) {
    private {
        int _size;
        T[] _data;
    }

    this(int N) {
        _size = N;
        _data = new T[](_size + 1);
    }

    void update(int i, T x) {
        i++;
        while (i <= _size) {
            _data[i] = max(_data[i], x);
            i += i & (-i);
        }
    }

    T pmax(int r) {
        T res = 0;
        while (r > 0) {
            res = max(res, _data[r]);
            r -= r & (-r);
        }
        return res;
    }
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
0