結果

問題 No.1715 Dinner 2
ユーザー sten_sansten_san
提出日時 2021-10-22 21:58:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 2,428 bytes
コンパイル時間 2,300 ms
コンパイル使用メモリ 209,408 KB
実行使用メモリ 7,156 KB
最終ジャッジ日時 2023-10-24 13:05:15
合計ジャッジ時間 4,739 ms
ジャッジサーバーID
(参考情報)
judge13 / 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 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 138 ms
6,364 KB
testcase_12 AC 114 ms
5,836 KB
testcase_13 AC 95 ms
5,308 KB
testcase_14 AC 113 ms
5,836 KB
testcase_15 AC 116 ms
5,836 KB
testcase_16 AC 108 ms
5,572 KB
testcase_17 AC 68 ms
4,780 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 15 ms
4,348 KB
testcase_26 AC 9 ms
4,348 KB
testcase_27 AC 10 ms
4,348 KB
testcase_28 AC 13 ms
4,348 KB
testcase_29 AC 13 ms
4,348 KB
testcase_30 AC 13 ms
4,348 KB
testcase_31 AC 14 ms
4,348 KB
testcase_32 AC 176 ms
7,156 KB
testcase_33 AC 169 ms
7,156 KB
testcase_34 AC 180 ms
7,156 KB
testcase_35 AC 175 ms
7,156 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

int main() {
    constexpr auto inf = INT_MAX / 2;
    constexpr auto lim = 100000000;

    int n, d; cin >> n >> d;
    auto p = vec<int>(uns, n);
    auto q = vec<int>(uns, n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i] >> q[i];
    }

    auto max = [](auto &v) {
        int max1 = 0, max2 = -1;

        for (int i = 0; i < size(v); ++i) {
            if (v[max1] <= v[i]) {
                max1 = i;
            }
        }

        for (int i = 0; i < size(v); ++i) {
            if ((max2 < 0 || v[max2] <= v[i]) && max1 != i) {
                max2 = i;
            }
        }

        return make_tuple(max1, max2);
    };

    auto dp = vec<int>(uns, d + 1, n);
    auto check = [&](int x) {
        for (auto &v : dp) {
            for (auto &e : v) {
                e = -inf;
            }
        }

        fill(begin(dp[0]), end(dp[0]), 0);
        for (int i = 1; i <= d; ++i) {
            auto [max1, max2] = max(dp[i - 1]);

            auto get = [&](int v) {
                if (max1 == v) {
                    return dp[i - 1][max2];
                }
                return dp[i - 1][max1];
            };

            for (int j = 0; j < n; ++j) {
                if (x <= get(j) - p[j]) {
                    chmax(dp[i][j], get(j) - p[j] + q[j]);
                }
            }
        }

        return x <= *max_element(begin(dp[d]), end(dp[d]));
    };

    int l = -lim, r = 1;
    while (1 < r - l) {
        int m = l + (r - l) / 2;

        if (check(m)) {
            l = m;
        }
        else {
            r = m;
        }
    }

    cout << l << endl;
}

0