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>
typedef long long ll;
using namespace std;
ll x;
int k;
ll sum[64];
ll a[64];
map<ll, ll> mp;
ll f(ll n) {
if (n < 0)
return 0;
if (n == 0)
return 1;
if (mp.count(n))
return mp[n];
mp[n] = 0;
ll& ret = mp[n];
int i = 0;
while ((1ll << (i + 1)) <= n)
i++;
ret += f((1ll << i) - 1);
ll mx = min(n, sum[i] / x);
ret += f(mx - (1ll << i));
return ret;
}
ll count_tastiness(ll xx, vector<ll> aa) {
x = xx;
k = 60;
while ((int)aa.size() < k)
aa.push_back(0);
for (int i = 0; i < k; i++)
a[i] = aa[i];
for (int i = 0; i < k; i++) {
sum[i] = a[i] * (1ll << i);
if (i != 0)
sum[i] += sum[i - 1];
}
mp.clear();
return f((1ll << k) - 1);
}
#ifdef LOCAL
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int kk;
ll xx;
cin >> kk >> xx;
vector<ll> aa(kk);
for (int i = 0; i < kk; i++)
cin >> aa[i];
cout << count_tastiness(xx, aa) << endl;
return 0;
}
#endif
# | 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... |