This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef LOCAL
#else
#include "biscuits.h"
#endif
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif
template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }
#ifdef LOCAL
#else
#endif
typedef __uint128_t int128;
ll count_tastiness(ll x, vector<ll> a) {
a.resize(60);
vector<ll> sum(60);
sum[0] = a[0];
for (int i = 1; i < 60; i++) {
sum[i] = sum[i - 1] / 2 + a[i];
}
vector<ll> dp(61);
dp[0] = 1;
for (int i = 1; i <= 60; i++) {
dp[i] = dp[i - 1];
if (sum[i - 1] >= x) {
ll need = max(0LL, x - a[i - 1]) * 2;
ll tot = 0;
for (int j = i - 2; j >= 0; j--) {
if (sum[j] >= x + need) {
tot += dp[j];
need = max(0LL, x + need - a[j]) * 2;
} else {
need = max(0LL, need - a[j]) * 2;
}
}
if (need == 0) {
tot++;
}
dp[i] += tot;
}
}
return dp[60];
}
#ifdef LOCAL
int main() {
// ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("file.in", "r", stdin);
int q;
cin >> q;
for (int qq = 0; qq < q; qq++) {
ll k, x;
cin >> k >> x;
vector<ll> a(k);
for (int i = 0; i < k; i++) {
cin >> a[i];
}
cout << "TEST " << qq + 1 << ": "<< count_tastiness(x, a) << '\n';
}
return 0;
}
#else
#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... |