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;
using ll = long long;
ll x;
vector<ll> a, sum;
map<ll, ll> dp;
ll solve(ll n) {
if (n <= 1) return n;
if (dp.find(n) != dp.end()) return dp[n];
int i = 63 - __builtin_clzll(n);
if ((1LL << i) == n) i--;
return dp[n] = solve(1LL << i) + solve(max(0LL, min(n, sum[i] / x + 1) - (1LL << i)));
}
long long count_tastiness(long long _x, std::vector<long long> _a) {
x = _x, a = _a;
sum.clear();
dp.clear();
while (a.size() < 60) a.push_back(0);
for (int i = 0; i < 60; i++) {
sum.push_back((sum.empty() ? 0LL : sum.back()) + a[i] * (1LL << i));
}
return solve(1LL << 60);
}
# | 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... |