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 <numeric>
#include <cstdio>
long long count_tastiness(long long x, std::vector<long long> a) {
int k = (int) a.size();
std::vector<long long> dp(k + 1);
dp[0] = 1;
for (int i = 0; i < k; ++i) {
std::vector<int> digit(i);
long long cur = 0;
for (int j = 0; j < i; ++j) {
cur += a[j];
digit[j] = (cur & 1);
cur /= 2;
}
cur += a[i];
dp[i + 1] = dp[i];
if (cur < x) {
continue;
}
if (i < k - 1 && cur >= 2 * x) {
dp[i + 1] *= 2;
continue;
}
// fprintf(stderr, "i = %d, cur = %lld\n", i, cur);
dp[i + 1] *= (cur / x);
++dp[i + 1];
cur %= x;
for (int j = i - 1; j >= 0; --j) {
cur = cur * 2 + digit[j];
if (cur >= x) {
dp[i + 1] += dp[j];
cur -= x;
}
}
}
// for (int i = 0; i <= k; ++i) {
// fprintf(stderr, "dp[1 << %d == %lld] = %lld\n", i, 1ll << i, dp[i]);
// }
return dp[k];
}
# | 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... |