提出 #62106483


ソースコード 拡げる

/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#ifdef EMT
#include "Header/stdc++.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;

#ifdef EMT
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T, typename T2> ostream& operator<<(ostream &os, const pair<T, T2> &obj) {
    return os << '{' << obj.first << ',' << obj.second << '}';
}
template<class TupType, size_t... I> void lamy_kawaii(ostream& os, const TupType& _tup, index_sequence<I...>) {
    // source: https://stackoverflow.com/a/41171552
    os << '{';
    (..., (cerr << (I == 0? "" : ",") << get<I>(_tup)));
    os << '}';
}
template<class... T> ostream& operator<<(ostream &os, const tuple<T...>& _tup) {
    lamy_kawaii(os, _tup, make_index_sequence<sizeof...(T)>());
    return os;
}
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
    cerr << "\e[1;33m" << s << " = [";
    while (l != r) {
        cerr << *l;
        cerr << (++l == r ? ']' : ',');
    }
    cerr << "\e[0m\n";
}
#else
#define debug(x) 48763
#define print(x) 48763
#endif

template<typename T, typename T2> istream& operator>>(istream &is, pair<T, T2> &obj) {
    is >> obj.first >> obj.second;
    return is;
}
template<typename T> istream& operator>>(istream &is, vector<T> &obj) {
    for (auto &x : obj)
        is >> x;
    return is;
}

#define YN(x) ((x) ? "YES" : "NO")
#define Yn(x) ((x) ? "Yes" : "No")
#define yn(x) ((x) ? "yes" : "no")
#define emilia_my_wife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
template<typename T>
using base_type = remove_cv_t<remove_reference_t<T>>;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
static int Lamy_is_cute = []() {
    emilia_my_wife
    return 48763;
}();
/*--------------------------------------------------------------------------------------*/

signed main() {
    int n, x;
    cin >> n >> x;
    vector<int> v(n), a(n), c(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i] >> a[i] >> c[i];
        v[i]--;
    }
    vector<vector<ll>> dp(3, vector<ll>(x + 1));
    for (int i = 0; i < n; i++) {
        for (int j = x; j >= c[i]; j--)
            dp[v[i]][j] = max(dp[v[i]][j], dp[v[i]][j - c[i]] + a[i]);
    }
    auto check = [&] (ll m) {
        ll res = 0;
        for (int i = 0; i < 3; i++) {
            bool ok = false;
            for (int j = 0; j <= x; j++) {
                if (dp[i][j] >= m) {
                    ok = true;
                    res += j;
                    break;
                }
            }
            if (!ok)
                return false;
        }
        return res <= x;
    };
    ll l = 0, r = 1e15;
    while (l < r) {
        ll m = (l + r) >> 1;
        if (check(m))
            l = m + 1;
        else
            r = m;
    }
    cout << l - 1 << '\n';
}

提出情報

提出日時
問題 E - Vitamin Balance
ユーザ JiKuai
言語 C++ 20 (gcc 12.2)
得点 450
コード長 3619 Byte
結果 AC
実行時間 16 ms
メモリ 3756 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 2
AC × 58
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3488 KiB
example_01.txt AC 1 ms 3636 KiB
hand_00.txt AC 1 ms 3484 KiB
hand_01.txt AC 10 ms 3676 KiB
hand_02.txt AC 1 ms 3604 KiB
hand_03.txt AC 9 ms 3612 KiB
hand_04.txt AC 1 ms 3512 KiB
hand_05.txt AC 1 ms 3600 KiB
hand_06.txt AC 16 ms 3696 KiB
hand_07.txt AC 2 ms 3632 KiB
hand_08.txt AC 1 ms 3560 KiB
hand_09.txt AC 1 ms 3448 KiB
hand_10.txt AC 16 ms 3560 KiB
random_00.txt AC 1 ms 3544 KiB
random_01.txt AC 1 ms 3576 KiB
random_02.txt AC 1 ms 3756 KiB
random_03.txt AC 1 ms 3580 KiB
random_04.txt AC 1 ms 3600 KiB
random_05.txt AC 1 ms 3504 KiB
random_06.txt AC 1 ms 3556 KiB
random_07.txt AC 2 ms 3608 KiB
random_08.txt AC 1 ms 3504 KiB
random_09.txt AC 2 ms 3600 KiB
random_10.txt AC 2 ms 3500 KiB
random_11.txt AC 2 ms 3632 KiB
random_12.txt AC 6 ms 3536 KiB
random_13.txt AC 6 ms 3712 KiB
random_14.txt AC 6 ms 3636 KiB
random_15.txt AC 1 ms 3496 KiB
random_16.txt AC 1 ms 3516 KiB
random_17.txt AC 1 ms 3576 KiB
random_18.txt AC 1 ms 3516 KiB
random_19.txt AC 1 ms 3592 KiB
random_20.txt AC 1 ms 3584 KiB
random_21.txt AC 2 ms 3520 KiB
random_22.txt AC 2 ms 3516 KiB
random_23.txt AC 1 ms 3580 KiB
random_24.txt AC 3 ms 3568 KiB
random_25.txt AC 2 ms 3492 KiB
random_26.txt AC 4 ms 3612 KiB
random_27.txt AC 8 ms 3704 KiB
random_28.txt AC 10 ms 3612 KiB
random_29.txt AC 4 ms 3512 KiB
random_30.txt AC 1 ms 3628 KiB
random_31.txt AC 1 ms 3488 KiB
random_32.txt AC 2 ms 3512 KiB
random_33.txt AC 1 ms 3564 KiB
random_34.txt AC 1 ms 3528 KiB
random_35.txt AC 1 ms 3564 KiB
random_36.txt AC 1 ms 3404 KiB
random_37.txt AC 2 ms 3500 KiB
random_38.txt AC 2 ms 3756 KiB
random_39.txt AC 1 ms 3428 KiB
random_40.txt AC 2 ms 3636 KiB
random_41.txt AC 2 ms 3576 KiB
random_42.txt AC 10 ms 3636 KiB
random_43.txt AC 14 ms 3684 KiB
random_44.txt AC 2 ms 3408 KiB