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;
int k;
long long X;
vector<long long> pref;
long long ans[65];
int logb2(long long x) {
int cnt = 0;
while(x>1) {
cnt++;
x/=2;
}
return cnt;
}
long long findans(long long x) {
if(x<=0) {
return 0;
}
if(x==1) {
return 1;
}
int LOG = logb2(x-1);
int LOG1 = logb2(x);
if(LOG != LOG1 && ans[LOG1]!=-1) {
return ans[LOG1];
}
long long v = findans(1LL<<LOG) + findans(min(x, 1+pref[LOG]/X) - (1LL<<LOG));
if(LOG != LOG1) {
ans[LOG1] = v;
}
return v;
}
long long count_tastiness(long long x, std::vector<long long> a) {
k = a.size(); X = x;
pref.resize(61); a.resize(61);
for(int i=0; i<=61; i++) ans[i] = -1;
for(int i=k; i<61; i++) {
a[i] = 0;
}
for(int i=0; i<61; i++) {
pref[i] = (1LL<<i) * a[i];
if(i) pref[i] += pref[i-1];
}
return findans(1LL<<61);
}
# | 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... |