이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
using ll = long long;
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
struct chash {
uint64_t operator()(uint64_t x) const {
x ^= x >> 31;
x ^= x << 17;
x ^= x >> 23;
return x;
}
};
const int maxn = 300;
int n;
long k, arr[maxn];
__gnu_pbds::gp_hash_table<long, long, chash> memo[maxn];
long dp(int ind, long prev) {
if (ind >= n && prev < k) {
return 1;
}
auto it = memo[ind].find(prev);
if (it != memo[ind].end()) {
return it->second;
}
long cur = arr[ind] + prev;
long ans = dp(ind + 1, cur / 2);
if (cur >= k) {
ans += dp(ind + 1, (cur - k) / 2);
}
return memo[ind][prev] = ans;
}
ll count_tastiness(ll _k, vector<ll> _arr) {
k = _k;
n = sz(_arr);
memset(arr, 0, sizeof(arr));
copy(begin(_arr), end(_arr), arr);
for (auto& a : memo) {
a.clear();
}
return dp(0, 0);
}
# | 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... |