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;
const int MAXK = 60;
vector<long long> s;
map<pair<long long, long long>, long long> M;
long long f(long long k, long long v){
if(M.count({k, v})) return M[{k, v}];
if(k == 0){
return M[{k, v}] = v > 0 ? 2 : 1;
}else{
long long res = 0;
if(v >= (1LL << k)) res += f(k - 1, min(v - (1LL << k), s[k - 1]));
res += f(k - 1, min(v, s[k - 1]));
return M[{k, v}] = res;
}
}
long long count_tastiness(long long x, vector<long long> a) {
M.clear();
a.resize(MAXK); s.resize(MAXK); vector<long long> pw2(MAXK);
pw2[0] = 1; for(int i = 1; i < MAXK; i++) pw2[i] = pw2[i - 1] * 2;
s[0] = a[0]; for(int i = 1; i < MAXK; i++) s[i] = s[i - 1] + a[i] * pw2[i];
for(int i = 0; i < MAXK; i++) s[i] = min((1LL << (i + 1)) - 1, s[i] / x);
long long ans = f(MAXK - 1, s[MAXK - 1]);
return ans;
}
# | 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... |