結果

問題 No.777 再帰的ケーキ
ユーザー kakira9618kakira9618
提出日時 2018-12-25 02:09:44
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,325 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 174,864 KB
実行使用メモリ 29,780 KB
最終ジャッジ日時 2024-04-08 16:20:55
合計ジャッジ時間 6,259 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,352 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 1 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 1 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 1 ms
6,548 KB
testcase_17 AC 3 ms
6,548 KB
testcase_18 AC 2 ms
6,548 KB
testcase_19 AC 1 ms
6,548 KB
testcase_20 AC 1 ms
6,548 KB
testcase_21 AC 11 ms
6,548 KB
testcase_22 AC 11 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 11 ms
6,548 KB
testcase_26 AC 12 ms
6,548 KB
testcase_27 AC 3 ms
6,548 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

// O(N^2), TLE解
int main() {
    int N;
    cin >> N;

    map<pll, ll> Cake_; // ケーキの情報 (一時保存用)
    vector<tuple<ll,ll,ll>> Cake; // ケーキの情報 (dpで使う時用)
    for(int i = 0; i < N; i++) {
        ll a, b, c;
        cin >> a >> b >> c;

        // aの昇順、aが同じ時はbの降順にソートしつつ、同じ大きさのケーキはカロリーの高いものだけを残す
        Cake_[{a, -b}] = max(Cake_[{a, -b}], c);
    }
    N = Cake_.size(); // 省いたケーキがある場合もあるのでNを更新
    
    // 簡単にアクセスするために中の要素を順番を保ちつつvectorに移し替える。Bのマイナスはもとに戻す
    for(auto c : Cake_) Cake.push_back(make_tuple(c.first.first, -c.first.second, c.second));

    // 動的計画法
    vector<ll> dp(N);
    for(int i = 0; i < N; i++) {
        dp[i] = get<2>(Cake[i]);
        for(int j = 0; j < i; j++) {
            if (get<1>(Cake[j]) >= get<1>(Cake[i])) continue; // Bに関する条件をチェック
            dp[i] = max(dp[i], dp[j] + get<2>(Cake[i]));
        }
    }

    cout << *max_element(all(dp)) << endl;

    return 0;    
}
0