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 "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "/home/eagle/ioi20/d2/debug.h"
#else
#define debug(...) void(37)
#endif
long long count_tastiness(long long X, std::vector<long long> A) {
int K = int(A.size());
for (int i = 0; i < K - 1; ++i) {
long long carry = max(0LL, (A[i] - X) / 2);
A[i] -= 2 * carry;
A[i + 1] += carry;
}
A.back() = min(A.back(), X);
vector<long long> dp(K);
long long prev = 1;
for (int i = K - 1; i >= 0; --i) {
if (A[i] >= X) {
prev = prev * 2 + dp[i];
continue;
}
long long need = (1LL << i) * X;
debug(i, prev);
for (int j = i; j >= 0; --j) {
long long have = (1LL << j) * A[j];
if (have >= need) {
dp[j] += prev;
have -= need;
need = (1LL << j) * X;
assert(have <= need);
if (have == need) {
dp[j] += prev;
break;
}
}
need -= have;
}
prev += dp[i];
}
return prev;
}
# | 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... |