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
std::map<ll, ll> dp;
const int K = 62;
ll s[K];
ll rec(ll n, ll x) {
if(n <= 0) return 0;
if(n == 1) return 1;
if(dp.count(n)) return dp[n];
ll largestSmaller = 0;
for(ll i = 0; i < K; ++i) {
if((1LL << i) < n) largestSmaller = i;
}
ll ans = rec((1LL << largestSmaller), x) + rec(std::min(n, 1 + s[largestSmaller] / x) - (1LL << largestSmaller), x);
dp[n] = ans;
return ans;
}
long long count_tastiness(long long x, std::vector<long long> a) {
dp.clear();
for(ll i = 0; i < K; ++i) s[i] = 0;
for(ll i = 0; i < (ll)a.size(); ++i) {
s[i] = a[i] * (1LL << i);
if(i) s[i] += s[i - 1];
}
for(ll i = (ll)a.size(); i < K; ++i) s[i] = s[i - 1];
if(s[(ll)a.size() - 1] < x) return 1;
return rec((s[(ll)a.size() - 1]) / x + 1, x);
}
# | 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... |