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 <bits/stdc++.h>
#define int long long
using namespace std;
#include "biscuits.h"
const int MAX = 101;
int dfs(const vector<int> &a, int nbRestants, int x, int curBit) {
if (curBit == MAX)
return 1;
if (curBit < (int)a.size())
nbRestants += a[curBit];
else if (nbRestants < x)
return 1;
int sol = dfs(a, nbRestants / 2, x, curBit + 1);
if (nbRestants >= x)
sol += dfs(a, (nbRestants - x) / 2, x, curBit + 1);
return sol;
}
using ll = __int128;
map<ll, int> dp;
void write(ll x) {
if (x >= 10)
write(x / 10);
cout << (int)(x % 10);
}
int solve(ll n, const vector<int> &a, int x, const vector<ll> &prefixSum) {
if (n <= 0)
return 0;
if (n == 1)
return 1;
if (dp.count(n))
return dp[n];
ll curPow = 1;
int i = 0;
while (2 * curPow < n) {
curPow *= 2;
i++;
}
int &ret = dp[n];
ret = solve(curPow, a, x, prefixSum);
ret += solve(min(n, 1 + prefixSum[i] / x) - curPow, a, x, prefixSum);
return ret;
}
int count_tastiness(int x, vector<int> a) {
while (a.size() < MAX)
a.push_back(0);
dp.clear();
vector<ll> prefixSum(MAX);
ll curPow = 1;
for (int i = 0; i < MAX; ++i) {
prefixSum[i] = (i ? prefixSum[i - 1] : 0) + curPow * a[i];
curPow *= 2;
}
// dp(n) = nb de sol < n
// si 2^i <= n < 2^n+1, alors
// dp(n) = dp[2^i] + dp[min(2^n, s[i]/x-2^i + 1)]
return solve(curPow / 2, a, x, prefixSum);
}
# | 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... |