Submission #405237

#TimeUsernameProblemLanguageResultExecution timeMemory
405237balbitPacking Biscuits (IOI20_biscuits)C++14
0 / 100
5 ms332 KiB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define pii pair<int, int>
#define f first
#define s second

#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int)((x).size())
#define pb push_back

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){ cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y){ cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT



const int maxn = 3e5+5;

ll cnt[62][62]; // number of constraints from these ones
ll lm[62]; // what's my constraint?

long long count_tastiness(long long x, std::vector<long long> a) {
    while(SZ(a) < 61) a.pb(0);
    int K = 61;
    ll sm = 0;
    for (int i = 0; i<K; ++i) {
        sm += (1ll<<i) * a[i];
        ll ho = sm / x;
        lm[i] = ho;
    }
    cnt[K-1][K-1] = 1;
    ll re = 0;
    for (int i = K-1; i>=0; --i) {
        ll msk = (1ll<<(i+1)) - 1;
        for (int frm = K-1; frm >= i; --frm) {
            if (cnt[i][frm]) {
                ll dis = lm[frm] & msk;
                if (dis > lm[i]) {
                    cnt[i][i] += cnt[i][frm];
                }else{
                    if (dis == 0) re += cnt[i][frm];
                    else{
                        if (dis >= (1ll<<i)) {
                            // can choose to not take
                            (i?cnt[i-1][i-1]:re) += cnt[i][frm];
                        }
                        {
                            // need to be restrained
                            (i?cnt[i-1][frm]:re) += cnt[i][frm];
                        }
                    }
                }
            }
        }
    }
    return re;

}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...