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/extc++.h>
#include "biscuits.h"
namespace {
using ll = long long;
template <class T> using Vec = std::vector<T>;
template <class T, class U> using HashTable = __gnu_pbds::gp_hash_table<T, U>;
template <class F> struct RecLambda: private F {
explicit RecLambda(F&& f): F(std::forward<F>(f)) {}
template <class... Args> decltype(auto) operator() (Args&&... args) const {
return F::operator()(*this, std::forward<Args>(args)...);
}
};
}
ll count_tastiness(ll x, Vec<ll> a) {
a.resize(60);
std::array<ll, 60> sum{};
for (int i = 0; i < 60; ++i) {
sum[i] = (i == 0 ? 0 : sum[i - 1]) + (a[i] << i);
}
HashTable<ll, ll> table;
table[1] = 1;
return RecLambda([&](auto&& dfs, const ll n) -> ll {
if (n <= 0) {
return 0;
}
if (table[n] != 0) {
return table[n];
}
int logn = 0;
while (((ll) 1 << (logn + 1)) < n) {
logn += 1;
}
return table[n] = dfs((ll) 1 << logn) + dfs(std::min(sum[logn] / x + 1, n) - ((ll) 1 << logn));
})((ll) 1 << 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... |