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 ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
using namespace std;
const int mod = 1000000007;
void add(int& a, int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
int mult(int a, int b) {
return a * (ll)b % mod;
}
int bp(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1) res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
ll dp[61][61];
ll count_tastiness(ll x, vector<ll> a) {
int k = a.size();
vector<ll> bounds;
ll sum = 0;
for (int i = 0; i < 60; ++i) {
if (i < k) sum += (1LL<<i)*a[i];
bounds.pb(sum / x);
}
for (int i = 0; i < 61; ++i) for (int j = 0; j < 61; ++j) dp[i][j] = 0;
dp[60][0] = 1;
for (int i = 60; i > 0; --i) {
for (int j = 0; j < 61; ++j) {
ll R = (1LL<<i) - 1;
if (j > 0) R = bounds[j - 1] % (1LL<<i);
ll C = bounds[i - 1];
//////////////////////////////// ZERO TRANSITION
if (R >= (1LL<<(i-1)) && C >= (1LL<<(i-1))) {
dp[i - 1][0] += dp[i][j];
}
else if (R <= C) {
dp[i - 1][j] += dp[i][j];
}
else {
dp[i - 1][i] += dp[i][j];
}
////////////////////////////////
if (R < (1LL<<(i-1)) || C < (1LL<<(i-1))) {
continue;
}
else if (R <= C) {
dp[i - 1][j] += dp[i][j];
}
else {
dp[i - 1][i] += dp[i][j];
}
}
}
ll ans = 0;
for (int j = 0; j < 61; ++j) ans += dp[0][j];
return ans;
}
#ifdef LOCAL
int main(){
freopen("A_input.txt", "r", stdin);
//freopen("A_output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int k;
ll x;
cin >> k >> x;
vector<ll> v(k);
for (auto &x : v) cin >> x;
cout << count_tastiness(x, v) << endl;
}
#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... |