#include "biscuits.h"
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
map<ll , ll> mp;
ll f(ll x){
int c = 0;
while(x){
x /= 2;
c ++;
}
return c;
}
ll get_ans(vector<ll> &a , ll x , ll lim){
if(lim < x) return (lim >= 0);
lim = min(lim , a[f(lim / x) - 1]);
if(mp.find(lim) != mp.end()) return mp[lim];
ll p = f(lim / x) - 1;
ll pw = (1 << p);
mp[lim] = (get_ans(a , x , (pw - 1) * x) + get_ans(a , x , min((pw - 1) * x , lim - pw * x)));
return mp[lim];
}
long long count_tastiness(long long x, std::vector<long long> A) {
mp.clear();
int k = A.size();
vector<ll> a(k);
a[0] = A[0];
for(ll i = 1;i < k; ++ i) a[i] = a[i - 1] + A[i] * (1ll << i);
int answ = get_ans(a , x , a.back());
return answ;
}
# | 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... |