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;
long long k;
long long ans[60],limit[60];
long long que(long long x,long long pos)
{
if(x>=limit[pos]) return ans[pos];
if(x<0) return 0;
if(pos==0) return x+1;
return que(x,pos-1)+que(x-(1ll<<pos),pos-1);
}
long long count_tastiness(long long x, std::vector<long long> a) {
k=a.size();
if(k==1) return a[0]/x+1;
limit[0]=a[0];
for(long long i=1;i<k;i++) limit[i]=limit[i-1]+(a[i]<<i);
for(int i=0;i<k-1;i++) limit[i]=min((1ll<<(i+1))-1,limit[i]/x);
limit[k-1]=limit[k-1]/x;
long long ext=limit[k-1]>>(k-1);
limit[k-1]%=(1ll<<(k-1));
ans[0]=limit[0]+1;
for(long long i=1;i<k;i++) ans[i]=que(limit[i],i-1)+que(limit[i]-(1ll<<i),i-1);
return ans[k-1]+ext*ans[k-2];
}
# | 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... |