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>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
typedef std::pair<ll,ll> pll;
using namespace std;
const int N = 64;
ll a[N], b[N];
map<pll,ll> mem;
int n;
ll solve(int k, ll mx)
{
mx = min(mx, (1ll<<k)-1);
if (k == 0 || mx == 0)
return 1;
auto &ans = mem[pll(k, mx)];
if (ans)
return ans;
ans += solve(k-1, min(mx, b[k-1]));
if (mx >= (1ll << (k-1)))
ans += solve(k-1, min(mx - (1ll << (k-1)), b[k-1]));
return ans;
}
long long count_tastiness(long long x, std::vector<long long> _a) {
n = _a.size();
Loop (i,0,n)
a[i] = _a[i];
ll sum = 0;
Loop (i,0,n) {
sum += a[i]<<i;
b[i+1] = sum/x;
}
mem.clear();
return solve(n, b[n]);
}
# | 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... |