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>
#pragma GCC optimize("O3")
#define endl '\n'
using namespace std;
long long pr[62];
unordered_map <long long, long long> dp[62];
long long f(int pos, long long sm, long long x) {
if (sm < 0)
return 0;
if (pos == -1 || sm == 0)
return 1;
sm = min(sm, (1ll << (pos + 1)) - 1);
if (dp[pos].count(sm))
return dp[pos][sm];
long long ans = f(pos-1, sm, x);
if (pr[pos] - (x << pos) >= 0) {
long long sm1 = min(sm - (1 << pos), (pr[pos] - (x << pos)) / x);
ans += f(pos-1, sm1, x);
}
return dp[pos][sm] = ans;
}
long long count_tastiness(long long x, vector <long long> a) {
pr[0] = a[0];
for (int i = 1; i <= 61; i++) {
pr[i] = pr[i-1];
if (i < (int)a.size())
pr[i] += (1ll << i) * a[i];
}
long long last = 0;
for (int i = 0; i <= 61; i++)
if ((x << i) > pr[61]) {
last = i-1;
break;
}
for (int i = 0; i <= last; i++)
dp[i].clear();
return f(last, (1ll << 61), x);
}
/*
int main() {
long long n, x;
cin >> x >> n;
vector <long long> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
cout << count_tastiness(x, v) << endl;
}
*/
# | 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... |