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 <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
vector<long long> trans(const vector<long long>& a, long long sub) {
vector<long long> na = a;
na.pop_back();
if (a.back() - sub > 1) {
long long val = (a.back() - sub) / 2;
if (na.size() == 0) na.push_back(val);
else na.back() += val;
}
return na;
}
map<vector<long long>, long long> f;
long long solve(long long x, vector<long long> a) {
if (a.size() == 0) return 1;
if (f.count(a)) return f[a];
long long ret = 0;
if (a.back() >= x) {
ret += solve(x, trans(a, x));
}
ret += solve(x, trans(a, 0));
return f[a] = ret;
}
long long count_tastiness(long long x, vector<long long> a) {
f.clear();
for (int i = 0; i < (int) a.size(); ++i) {
if (a[i] > x) {
long long add = (a[i] - x) / 2;
a[i] = x + ((a[i] - x) & 1);
if (i + 1 == (int) a.size())
a.push_back(add);
else
a[i + 1] += add;
}
}
reverse(a.begin(), a.end());
return solve(x, a);
}
# | 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... |