QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#380539#5303. No Bug No Gamekevinyang#WA 87ms5504kbC++209.0kb2024-04-07 05:38:092024-04-07 05:38:10

Judging History

你现在查看的是最新测评结果

  • [2024-04-07 05:38:10]
  • 评测
  • 测评结果:WA
  • 用时:87ms
  • 内存:5504kb
  • [2024-04-07 05:38:09]
  • 提交

answer

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

/* Macros {{{ */
/*  A lot of this is from some of Benq's submissions
    [https://codeforces.com/profile/Benq]
    Ugly af to the eyes, but with vim fold its barable
    Hopefully c++20 concepts can make all this stuff must cleaner */

/* Basics {{{ */
using ll = long long;
using ld = long double;
using str = string;

using pi = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
#define mp make_pair
#define fi first
#define se second

#define arr array
#define ve vector
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;

using vpi = vector<pi>;
using vpll = vector<pll>;
using vpld = vector<pld>;

using vvi = vector<vi>;
using vvll = vector<vll>;
using vvld = vector<vld>;

using vvpi = vector<vpi>;
using vvpll = vector<vpll>;
using vvpld = vector<vpld>;

#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz size()
#define rsz(a) resize(a)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#define For(i, a, b) for (int i = a; i < b; ++i)
#define Rof(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define rep(a) For(_, 0, a)
#define each(a, x) for (auto &a : x)
#define reach(a, x) for (auto a = x.rbegin(); a != x.rend(); ++a)

template <typename T, typename U>
inline void cmin(T &x, U y) {
    if (y < x) x = y;
}
template <typename T, typename U>
inline void cmax(T &x, U y) {
    if (x < y) x = y;
}
/*}}}*/

/* IO {{{ */

/* Template Macros {{{ */
#define tcT template <class T
#define tcTU tcT, class U
#define tcTUU tcT, class... U
/*}}}*/

inline namespace Helpers { /*{{{*/
tcT, class = void > struct is_iterable : false_type {};
tcT > struct is_iterable<
          T, void_t<decltype(begin(declval<T>())), decltype(end(declval<T>()))>>
    : true_type {};
tcT > constexpr bool is_iterable_v = is_iterable<T>::value;

tcT, class = void > struct is_readable : false_type {};
tcT > struct is_readable<T, typename std::enable_if_t<is_same_v<
                                decltype(cin >> declval<T &>()), istream &>>>
    : true_type {};
tcT > constexpr bool is_readable_v = is_readable<T>::value;

tcT, class = void > struct is_printable : false_type {};
tcT > struct is_printable<T, typename std::enable_if_t<is_same_v<
                                 decltype(cout << declval<T>()), ostream &>>>
    : true_type {};
tcT > constexpr bool is_printable_v = is_printable<T>::value;
} /* namespace Helpers */
/*}}}*/

inline namespace Input { /*{{{*/
tcT > constexpr bool needs_input_v = !is_readable_v<T> && is_iterable_v<T>;
tcTUU > void re(T &t, U &...u);
tcTU > void re(pair<T, U> &p); /* pairs */

/* re: read{{{ */
tcT > typename enable_if<is_readable_v<T>, void>::type re(T &x) {
    cin >> x;
} /* default */
tcT > typename enable_if<needs_input_v<T>, void>::type re(
          T &i);                                   // vectors, arrays, etc...
tcTU > void re(pair<T, U> &p) { re(p.fi, p.se); }  // pairs
tcT > typename enable_if<needs_input_v<T>, void>::type re(T &i) {
    each(x, i) re(x);
}
tcTUU > void re(T &t, U &...u) {
    re(t);
    re(u...);
} /* read multiple}}} */

/* rv: resize and read vectors{{{ */
void rv(size_t) {}
tcTUU > void rv(size_t N, ve<T> &t, U &...u);
template <class... U>
void rv(size_t, size_t N2, U &...u);
tcTUU > void rv(size_t N, ve<T> &t, U &...u) {
    t.rsz(N);
    re(t);
    rv(N, u...);
}
template <class... U>
void rv(size_t, size_t N2, U &...u) {
    rv(N2, u...);
} /*}}}*/

/* dumb shortcuts to read in ints{{{ */
void decrement() {} /* subtract one from each */
tcTUU > void decrement(T &t, U &...u) {
    --t;
    decrement(u...);
}
#define ints(...)    \
    int __VA_ARGS__; \
    re(__VA_ARGS__);
#define int1(...)      \
    ints(__VA_ARGS__); \
    decrement(__VA_ARGS__); /*}}}*/
} /* namespace Input */
/*}}}*/

inline namespace ToString { /*{{{*/
tcT > constexpr bool needs_output_v = !is_printable_v<T> && is_iterable_v<T>;

/* ts: string representation to print */
tcT > typename enable_if<is_printable_v<T>, str>::type ts(T v) {
    stringstream ss;
    ss << fixed << setprecision(15) << v;
    return ss.str();
} /* default */
tcT > str bit_vec(T t) { /* bit vector to string */
    str res = "{";
    For(i, 0, t.sz) res += ts(t[i]);
    res += "}";
    return res;
}
str ts(ve<bool> v) { return bit_vec(v); }
template <size_t SZ>
str ts(bitset<SZ> b) {
    return bit_vec(b);
} /* bit vector */
tcTU > str ts(pair<T, U> p); /* pairs */
tcT > typename enable_if<needs_output_v<T>, str>::type ts(
          T v); /* vectors, arrays */
tcTU > str ts(pair<T, U> p) { return "(" + ts(p.fi) + ", " + ts(p.se) + ")"; }
tcT > typename enable_if<is_iterable_v<T>, str>::type ts_sep(T v, str sep) {
    /* convert container to string w/ separator sep */
    bool fst = 1;
    str res = "";
    for (const auto &x : v) {
        if (!fst) res += sep;
        fst = 0;
        res += ts(x);
    }
    return res;
}
tcT > typename enable_if<needs_output_v<T>, str>::type ts(T v) {
    return "{" + ts_sep(v, ", ") + "}";
}

/* for nested DS */
template <int, class T>
typename enable_if<!needs_output_v<T>, ve<str>>::type ts_lev(const T &v) {
    return {ts(v)};
}
template <int lev, class T>
typename enable_if<needs_output_v<T>, ve<str>>::type ts_lev(const T &v) {
    if (lev == 0 || !v.sz) return {ts(v)};
    ve<str> res;
    for (const auto &t : v) {
        if (res.sz) res.back() += ",";
        ve<str> tmp = ts_lev<lev - 1>(t);
        res.insert(end(res), all(tmp));
    }
    For(i, 0, res.sz) {
        str bef = " ";
        if (i == 0) bef = "{";
        res[i] = bef + res[i];
    }
    res.back() += "}";
    return res;
}
} /* namespace ToString */
/*}}}*/

inline namespace Output { /*{{{*/
template <class T>
void pr_sep(ostream &os, str, const T &t) {
    os << ts(t);
}
template <class T, class... U>
void pr_sep(ostream &os, str sep, const T &t, const U &...u) {
    pr_sep(os, sep, t);
    os << sep;
    pr_sep(os, sep, u...);
}
/* print w/ no spaces */
template <class... T>
void pr(const T &...t) {
    pr_sep(cout, "", t...);
}
/* print w/ spaces, end with newline */
void ps() { cout << "\n"; }
template <class... T>
void ps(const T &...t) {
    pr_sep(cout, " ", t...);
    ps();
}
/* debug to cerr */
template <class... T>
void dbg_out(const T &...t) {
    pr_sep(cerr, " | ", t...);
    cerr << endl;
}
void loc_info(int line, str names) {
    cerr << "Line(" << line << ") -> [" << names << "]: ";
}
template <int lev, class T>
void dbgl_out(const T &t) {
    cerr << "\n\n" << ts_sep(ts_lev<lev>(t), "\n") << "\n" << endl;
}
} /* namespace Output */
/*}}}}}}}}}*/

int n, k;

vi p;
vvi w;
vvi buckets;

void solve() {
    re(n, k);
    p.resize(n), w.resize(n);
    for(int i=0; i<n; ++i) re(p[i]), rv(p[i], w[i]);


    int tot_power = accumulate(all(p), 0);
    if(tot_power <= k) {
        int res = 0;
        for(int i=0; i<n; ++i) res += w[i][p[i]-1];
        ps(res);
        return;
    }


    buckets.assign(11, vi());
    for(int i=0; i<n; ++i) buckets[p[i]].pb(i);


    vvi opt_assignment(11, vi(k+1, 0)); // opt_assignment[b][k] is the optimal value that can be achevied with values from bucket b that sum to k
    for(int b=1; b<=10; ++b) {
        if(buckets[b].sz == 0) continue;

        vpi sb(buckets[b].sz);
        for(int i=0; i<buckets[b].sz; ++i) sb[i] = { w[buckets[b][i]][b-1], buckets[b][i] };
        sort(all(sb), greater{});

        for(int residue=1; residue<=b; ++residue) {

            int osum = 0;
            for(int taken=1; taken<=buckets[b].sz && (taken-1)*b + residue <= k; ++taken) {
                osum += sb[taken-1].fi;

                for(int li=0; li<buckets[b].sz; ++li) {
                    int cv = osum - ( (li < taken) ? sb[li].fi : sb[taken-1].fi ) + w[sb[li].se][residue-1];
                    cmax(opt_assignment[b][(taken-1)*b + residue], cv);
                }

            }

        }
    }

    ve<vvi> dp(11, vvi(k+1, vi(2, 0)));

    for(int b=1; b<=10; ++b) {
        for(int sum=0; sum<=k; ++sum) {
            for(int diff=0; diff<=sum; ++diff) {

                if(diff % b == 0) {
                    cmax(dp[b][sum][0], dp[b-1][sum-diff][0] + opt_assignment[b][diff]);
                    cmax(dp[b][sum][1], dp[b-1][sum-diff][1] + opt_assignment[b][diff]);
                }

                cmax(dp[b][sum][1], dp[b-1][sum-diff][0] + opt_assignment[b][diff]);
            }
        }
    }

    ps(dp[10][k][1]);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /* cout << fixed << setprecision(6); */
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; i++) solve();

    return 0;
    // you should actually read the stuff at the bottom
}

/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 * DON'T GET STUCK ON ONE APPROACH
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3560kb

input:

4 5
2 1 3
2 1 1
2 3 1
2 1 3

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 87ms
memory: 5436kb

input:

3000 3000
10 70562 30723 79371 82224 63977 3362 26909 96449 48163 66159
4 18007 33590 80674 91139
4 10304 31694 70745 50656
10 63090 17226 13187 73881 38137 15237 55750 82751 75854 39658
8 95640 66120 87735 36388 44046 92415 6952 94772
9 60565 27904 98726 87052 35768 25453 14563 34273 92501
10 66332...

output:

68279788

result:

ok 1 number(s): "68279788"

Test #3:

score: 0
Accepted
time: 86ms
memory: 5500kb

input:

3000 3000
7 63414 1471 67699 90007 79945 68096 24021
8 88988 13255 69503 8350 23580 4589 13918 43025
2 7666 45786
2 23237 48565
9 46170 76160 31929 26707 99 76847 64227 82880 99490
8 45937 52389 61039 13440 76101 49424 68485 47682
4 71757 34559 95339 27693
10 55332 93329 61008 26946 44148 73675 3776...

output:

70716917

result:

ok 1 number(s): "70716917"

Test #4:

score: 0
Accepted
time: 87ms
memory: 5428kb

input:

3000 3000
6 54485 55856 50343 67667 49501 76096
4 12436 88408 78352 13780
4 50966 49067 59688 80332
9 46560 57602 70521 97371 46436 28009 53076 80935 97421
3 95153 3255 48822
1 90375
6 55198 58182 28379 61019 61215 89332
8 64049 67076 1987 43389 6895 64126 73017 60143
2 5359 39166
9 95803 92377 3672...

output:

72397846

result:

ok 1 number(s): "72397846"

Test #5:

score: 0
Accepted
time: 87ms
memory: 5448kb

input:

3000 3000
3 14784 32621 10730
7 66753 68601 10513 54658 95258 95000 26583
6 34297 97982 2242 91140 81325 57369
3 74322 55419 79533
9 26303 72513 25009 44015 57763 67938 65018 8793 18127
2 86236 22018
1 81085
5 97826 41038 57779 13095 94954
6 79827 5618 303 78145 32358 90650
9 62675 32720 44809 96682...

output:

72850557

result:

ok 1 number(s): "72850557"

Test #6:

score: 0
Accepted
time: 83ms
memory: 5504kb

input:

3000 3000
6 43825 58567 56450 53586 60432 86517
4 92930 45704 521 86800
10 94044 49579 5307 5298 73535 77229 78590 12737 91879 62875
7 8629 84121 14470 90067 28955 69428 289
9 19202 37347 28852 92595 71071 41474 53853 14859 54245
9 99091 1842 28972 80370 19521 56913 4856 47022 80824
4 7788 85510 201...

output:

68404953

result:

ok 1 number(s): "68404953"

Test #7:

score: -100
Wrong Answer
time: 83ms
memory: 5500kb

input:

3000 3000
10 92976 94648 92081 95888 91848 93242 92861 90288 99524 96601
10 98101 95964 98594 98546 95280 99393 97812 91256 90283 95955
10 97392 91631 91892 90882 90363 94526 93325 94802 94885 91760
10 93909 96486 96811 98728 90934 93073 97550 96420 93808 90042
10 92203 98501 97290 99608 94936 97826...

output:

29847721

result:

wrong answer 1st numbers differ - expected: '29846657', found: '29847721'