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>
#define ll long long
using namespace std;
const int k=61;
int i;
int nearest(ll u){
vector<int> v;
while(u>0){
v.push_back(u%2);
u/=2;
}
for(int i=v.size()-1; i>=0; i--){
if(v[i]==1) return i;
}
return -1;
}
long long count_tastiness(long long x, vector<long long> a) {
vector<ll> s(k+1),ans(k+1), s1(k+1);
int n=a.size();
for(i=0; i<n; i++){
ll p=pow(2,i);
//s[i]=(long long)((double)a[i]/x*pow(2,i));
s[i]=a[i]*p/x;
s1[i]=((a[i]%x)*((ll)pow(2,i)%x))%x;
}
for(i=1; i<k; i++){
s[i]+=s[i-1];
s1[i]+=s1[i-1];
s[i]+=s1[i]/x;
s1[i]%=x;
}
ans[0]=1;
for(i=1; i<k; i++){
ans[i]+=ans[i-1];
int j=i-1;
ll c=1; ll p;
int t=0;
while(c>0){
p=pow(2,j);
if(t==0) c=min(s[j],2*p-1)-p;
else c=min(s[j], c)-p;
if(c==0){
ans[i]++;
break;
}
if(c<0) break;
//if(i==58) cout<<c<<endl;
j=nearest(c);
ans[i]+=ans[j];
t++;
}
//cout<<i<<" "<<ans[i]<<endl;
}
return ans[k-1];
return 0;
}
# | 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... |