This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
memset(cnt, 0, sizeof cnt);
memset(lm, 0, sizeof lm);
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |