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 <unordered_map>
using namespace std;
const int kMaxK = 127;
typedef long long int64;
#define DEBUG if(0)
long long count_tastiness(int64 x, std::vector<int64> a) {
a.resize(kMaxK, 0);
for (int i = 0; i + 1 < kMaxK; i += 1) {
if (a[i] > x) {
int64 carry = (a[i] - x) / 2;
a[i + 1] += carry;
a[i] -= carry * 2;
}
}
DEBUG {
for (int i = 0; i < 10; i += 1) {
cerr << a[i] << '\t';
}
cerr << '\n';
}
unordered_map<int64, int64> old = { {0, 1} };
int64 ans = 1;
for (int i = 0; i < kMaxK; i += 1) {
unordered_map<int64, int64> new_dp;
for (auto& itr : old) {
int64 carry = itr.first;
int64 num = itr.second;
if (carry + a[i] >= x) {
DEBUG cerr << "Add + for " << i << '\n';
ans += num;
new_dp[(carry + a[i] - x) / 2] += num;
}
new_dp[(carry + a[i]) / 2] += num;
}
old = new_dp;
}
return ans;
}
# | 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... |