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>
using namespace std;
#define pb push_back
using ll = long long;
const int K = 60;
const ll INF = 1e18;
bool check (ll x, ll p) {
for (int i = 1; i <= p; i++) {
x *= 2;
if (x >= INF)
return false;
}
return true;
}
ll count_tastiness (ll x, vector <ll> a) {
a.resize (K);
vector <ll> sum (1 + K);
vector <ll> dp (1 + K);
for (int i = 0; i < K; i++)
sum[i + 1] = sum[i] + (a[i] << i);
dp[K] = 1;
for (int i = K; i > 0; i--) {
ll lb = sum[i], rb = sum[i];
for (int j = i - 1; j >= 0; j--) {
if (check (x, j)) {
if (lb >= (x << j))
lb -= (x << j);
if (rb >= sum[j]) {
if (lb <= rb)
dp[j] += dp[i] * (1 + (rb - max (lb, sum[j])) / (x << j));
rb -= (1 + (rb - sum[j]) / (x << j)) * (x << j);
}
}
}
}
return dp[0];
}
/**
int main () {
int n;
ll x;
cin >> n >> x;
vector <ll> v;
for (int i = 1; i <= n; i++) {
ll val;
cin >> val;
v.pb (val);
}
cout << count_tastiness (x, v) << "\n";
return 0;
}
**/
# | 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... |