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 <algorithm>
#include <vector>
typedef long long ll;
std::vector<long long> a;
ll x;
ll s[105],f[105];
bool chkmin(ll &a,ll b){return a>b?a=b,1:0;}
ll dfs(int x,ll y){
chkmin(y,s[x]);
if(!x){return std::min(y,s[x])+1;}
if(y<s[x-1])return dfs(x-1,y);
if(s[x-1]+(1ll<<x)<=y)return f[x-1]<<1;
if(y>=(1ll<<x))return f[x-1]+dfs(x-1,y-(1ll<<x));
return f[x-1];
}
long long count_tastiness(long long X, std::vector<long long> A) {
while(A.size()<60)A.emplace_back(0);
x=X;a=A;
int k=a.size();
ll cur=0;
for(int i=0;i<k;++i){
s[i]=std::min((cur+=a[i]<<i)/x,(1ll<<(i+1))-1);
}
f[0]=s[0]+1;
for(int i=1;i<k;++i){
f[i]=dfs(i,(1ll<<(i+1))-1);
}
return f[k-1];
}
# | 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... |