結果

問題 No.777 再帰的ケーキ
ユーザー rpy3cpprpy3cpp
提出日時 2019-05-06 03:06:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,662 bytes
コンパイル時間 1,795 ms
コンパイル使用メモリ 180,932 KB
実行使用メモリ 17,888 KB
最終ジャッジ日時 2023-09-08 17:23:04
合計ジャッジ時間 6,459 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 137 ms
5,424 KB
testcase_29 AC 137 ms
5,484 KB
testcase_30 AC 158 ms
5,420 KB
testcase_31 AC 159 ms
5,488 KB
testcase_32 AC 203 ms
17,816 KB
testcase_33 AC 37 ms
4,616 KB
testcase_34 AC 55 ms
5,404 KB
testcase_35 AC 117 ms
5,348 KB
testcase_36 AC 198 ms
17,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct Cake{
    int a, b, c;
    bool operator<(const Cake& right) const{
        return a == right.a ? b > right.b : a < right.a;
    }
};


void select_cakes(vector<Cake> & src){
    int j = 0;
    for (int i = 1; i < src.size(); ++i){
        if (src[j].a == src[i].a and src[j].b == src[i].b){
            src[j].c = max(src[j].c, src[i].c);
        }else{
            ++j;
            src[j] = src[i];
        }
    }
    src.erase(src.begin()+j+1, src.end());
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<Cake> cakes(N, Cake{0, 0, 0});
    for (auto & cake : cakes) cin >> cake.a >> cake.b >> cake.c;
    sort(cakes.begin(), cakes.end());
    select_cakes(cakes);
    map<int, long long> dp;
    dp[0] = 0LL;
    for (auto & cake : cakes){
        auto it = dp.upper_bound(cake.b);
        --it;
        if (it->first == cake.b){
            --it;
            long long val = it->second + cake.c;
            ++it;
            if (it->second >= val){
                continue;
            }else{
                it->second = val;
                ++it;
                auto jt = it;
                while (jt != dp.end() and jt->second <= val) ++jt;
                dp.erase(it, jt);
            }
        }else{
            long long val = it->second + cake.c;
            dp[cake.b] = val;
            auto it = dp.find(cake.b);
            ++it;
            auto jt = it;
            while (jt != dp.end() and jt->second <= val) ++jt;
            dp.erase(it, jt);
        }
    }
    cout << dp.rbegin()->second << endl;
    return 0;
}

0