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;
using lll = __int128_t;
const int K = 60;
const ll INF = 1e18;
ll count_tastiness (ll _x, vector <ll> a) {
a.resize (K);
vector <lll> sum (1 + K);
vector <lll> dp (1 + K);
for (int i = 0; i < K; i++)
sum[i + 1] = sum[i] + (a[i] << i);
lll x = _x;
dp[K] = 1;
for (int i = K; i > 0; i--) {
lll lb = sum[i], rb = sum[i];
for (int j = i - 1; j >= 0; 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... |