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 int long long
using namespace std;
map <int,int> f;
int s[61];
int x2;
int solve(int nr){
if(f.find(nr) != f.end())return f[nr];
///find answer
int ans = 0;
if(nr < 0)ans= 0;
else if(nr == 0)ans = 1;
else{
int nr2 = 0;
while((1LL<<(nr2 + 1)) <= nr)nr2++;
//cout<<nr<<' '<<(1ll<<nr2) - 1<<'\n';
ans+=solve((1ll<<nr2) - 1);
ans+=solve(min(nr, s[nr2]/x2) - (1ll<<nr2));
}
f[nr] = ans;
return f[nr];
}
long long count_tastiness(long long x, std::vector<long long> a) {
x2 = x;
int k = 60;
int sum = 0;
a.resize(60);
for(int i = 0;i < k - 1;i++){
int nr = max(0ll,a[i] - x)/2*2;
a[i]-=nr;
a[i + 1]+=nr/2;
}
for(int i = 0;i < k;i++){
sum+=(1ll<<i)*a[i];
s[i] = sum;
}
//cout<<sum/x<<' ';
return solve(sum/x);
}
/**
1
3 3
5 2 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... |