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>
long long count_tastiness(long long x, std::vector <long long> a) {
std::vector <long long> tmp(61, 0);
a.insert(a.end(), tmp.begin(), tmp.end());
std::vector <long long> pre(61, 0);
pre[0] = a[0];
for (int i = 1; i <= 60; i++) {
pre[i] = pre[i - 1] + a[i] * (1LL << i);
}
std::map <long long, long long> dp;
auto f = [&] (auto&& self, long long val) -> long long {
if (val < 0LL) {
return 0;
}
if (!val) {
return 1LL;
}
if (dp.count(val)) {
return dp[val];
}
return dp[val] = self(self, (1LL << (63LL - __builtin_clzll(val))) - 1) + self(self, std::min(val, pre[63 - __builtin_clzll(val)] / x) - (1LL << (63LL - __builtin_clzll(val))));
};
return f(f, 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... |