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;
typedef long long ll;
int k;
ll x;
vector<ll> s;
unordered_map<ll,ll> m;
int lg2(ll x){
int l=0,h=60,m,r=1;
while(l<=h){
m=(l+h)/2;
if((1ll<<m)<x)r=m,l=m+1;
else h=m-1;
}
return r;
}
ll dp(ll n){
if(n<=0)return 0;
if(n==1)return 1;
if(m[n]!=0)return m[n];
int i=lg2(n);
return m[n]=dp(1ll<<i)+dp(min(n,1+s[i]/x)-(1ll<<i));
}
ll count_tastiness(ll _x,vector<ll> a){
s.resize(60);
x=_x;
while((int)a.size()<60)a.push_back(0);
for(int i=0;i<60;++i){
s[i]=a[i]*(1ll<<i);
if(i!=0)s[i]+=s[i-1];
}
m.clear();
return dp((1ll<<60));
}
# | 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... |