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<bits/stdc++.h>
#include "biscuits.h"
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
long long mx[61];
map<long long,long long>f[61];
//k hieu sao ac ???
long long cal(long long val,int bit){
if (bit==0){
return f[bit][val]=min(val,mx[bit])+1;
}
if (f[bit].find(val)!=f[bit].end())return f[bit][val];
long long ans=cal(val,bit-1);
if (val>=(1ll<<bit)&&mx[bit]>=(1ll<<bit)){
ans+=cal(min(val-(1ll<<bit),mx[bit]-(1ll<<bit)),bit-1);
}
return f[bit][val]=ans;
}
long long count_tastiness(long long x, std::vector<long long> a) {
while (sz(a)<60)a.pb(0);
int n=sz(a);
long long sum=0;
for1(i,0,n-1){
sum+=(1ll<<i)*a[i];
mx[i]=min(sum/x,(1ll<<(i+1))-1);
f[i].clear();
}
return cal(mx[59],59);
}
# | 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... |