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>
typedef long long ll;
using namespace std;
vector<ll> A;
ll X;
map<ll, ll> calc(set<ll> &st, int k){
if (!k){
map<ll, ll> ret;
ret[0] = 1;
ret[1] = ret[0] + (A[0]>=X);
return ret;
}
ll S = 0;
for (int i=0;i<=k;i++) S += (1LL<<i)*A[i];
ll c = S/X, mx1 = (1LL<<k)-1;
set<ll> tmp;
if (c<(1LL<<(k+1))) tmp.insert(c&((1LL<<k)-1));
for (auto &val:st) tmp.insert(val&mx1);
map<ll, ll> tmp2 = calc(tmp, k-1), ret;
if (c<(1LL<<(k+1)) && c>mx1) ret[c] = tmp2[mx1]+tmp2[c&mx1];
else if (c<=mx1) ret[c] = tmp2[c];
for (auto &val:st){
if (val<=mx1) ret[val] = tmp2[val];
else if (val<=c){
ret[val] = tmp2[mx1]+tmp2[val&mx1];
}
else ret[val] = ret[c];
}
return ret;
}
long long count_tastiness(long long x, vector<long long> a) {
A = a;
X = x;
ll S = 0;
int k = (int)A.size()-1;
for (;!A[k];k--);
for (int i=0;i<=k;i++) S += (1LL<<i)*A[i];
//printf(" %d ", k);
if (!k) return S/x+1;
if (k<0) return 1;
ll mx = (1LL<<k)-1, q = (A[k]-1)/x+1;
ll sr = (S/x)&mx;
set<ll> tmp;
tmp.insert(mx);
tmp.insert(sr);
map<ll, ll> M = calc(tmp, k-1);
//printf("%lld %lld\n", M[mx], M[sr]);
ll ans = M[mx]*q;
ans += ((S/x)/(1LL<<k)+1-q)*M[mx];
ans -= M[mx] - M[sr];
return ans;
}
# | 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... |