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 <bits/stdc++.h>
#include "biscuits.h"
using ll = long long;
using std::vector;
using std::array;
using std::pair;
ll count_tastiness(ll x, vector<ll> a) {
a.resize(60);
array<ll, 60> max;
ll sum = 0;
for (int i = 0; i < 60; ++i) {
sum += a[i] << i;
max[i] = sum / x;
}
std::map<pair<int, ll>, ll> memo;
auto dfs = [&](auto&& self, int d, ll y) -> ll {
y = std::min(y, (1ll << (d + 1)) - 1);
if (d == -1) {
return 0;
}
if (const auto itr = memo.find(pair(d, y)); itr != memo.end()) {
return itr->second;
}
const ll ub = std::min(max[d], y) - (1ll << d);
if (ub >= 0) {
ll ret = 1;
for (int k = 0; k < d; ++k) {
ret += self(self, k, ub);
}
return memo[{d, y}] = ret;
} else {
return memo[{d, y}] = 0;
}
};
ll ret = 1;
for (int k = 0; k < 60; ++k) {
ret += dfs(dfs, k, 1ll << 60);
}
return ret;
}
# | 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... |