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 <vector>
#include <iostream>
long long count_tastiness(long long X, std::vector<long long> A) {
auto get_A = [&](int i) { return i < int(A.size()) ? A[i] : 0; };
std::vector<long long> len(121);
len[0] = 1;
std::vector<long long> max_elt(121); // floor of the max element
max_elt[0] = 0;
for (int i = 0; i < 120; i++) {
max_elt[i+1] = (get_A(i) + max_elt[i]) / 2;
len[i+1] = 0;
long long cutoff = 0;
for (int j = i; j >= 0; j--) {
cutoff *= 2;
cutoff -= get_A(j);
if (max_elt[j] >= cutoff + X) {
len[i+1] += len[j];
cutoff += X;
}
cutoff = std::max(cutoff, 0ll);
}
len[i+1]++; // the final 0
}
return len.back();
}
// poss_carry = [0]
// for i in range(120):
// poss_carry = [a[i] + v for v in poss_carry]
// poss_carry = [v - x for v in poss_carry if v >= x] + poss_carry
// poss_carry = [v / 2 for v in poss_carry]
// assert max(poss_carry) - min(poss_carry) < x
// mem[i+1] = poss_carry
// return len(poss_carry)
# | 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... |