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;
#define ll long long
map<ll, ll> res;
const ll MAX = 1'000'000'000'000'000'000;
ll s[100];
ll find(ll r){
if(r < 0) return 0;
if(r == 0) return 1;
if(res.count(r))
return res[r];
int i = (int)floor(log2(r));
while((1LL << i ) > r )
--i;
return res[r] = find((1LL << i) - 1) + find(min(r, s[i])- (1LL << i));
}
long long count_tastiness(long long x, std::vector<long long> a) {
res.clear();
while(a.size() < 60)
a.push_back(0);
for(int i = 0; i < 59; ++i){
ll t = max(0LL, (a[i] - x) / 2);
a[i] -= t * 2;
a[i + 1] += t;
}
a[59] = min(a[59], x + 1);
ll t = 0;
s[0] = a[0] / x;
t = a[0] % x;
for(int i = 1; i < 60; ++i){
s[i] = s[i - 1];
for(int j = i; j > 0; --j){
while(a[i] >= x){
s[i] = min(MAX, s[i] + (1LL << j));
a[i] -= x;
}
a[i] <<= 1;
}
while(a[i] >= x){
a[i] -= x;
++s[i];
}
t += a[i];
while(t >= x){
t -= x;
++s[i];
}
}
return find(MAX);
}
# | 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... |