#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(x) (cout << (x))
#else
#define dbg(x)
#endif
typedef long long ll;
using vi =vector<int>;
using vl = vector<ll>;
#define pb push_back
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define trace(x) for (auto &el : x) {dbg(el); dbg(" ");}
ll count_tastiness(ll x, vl a) {
int k = a.size();
const int BITS = 31;
ll SUM = 0;
for (int i = 0; i < k; i++) SUM += a[i] * (1 << i);
SUM /= x;
a.resize(max(k, BITS));
trace(a); dbg("\n");
// dbg("x: "); dbg(x); dbg(" k: "); dbg(k); dbg("\n");
ll ans = 0;
for (int sum = 0; sum <= SUM; sum++) {
vi tmpa(a.begin(), a.end());
vi needed(BITS); for (int i = 0; i < BITS; i++) if (sum & (1 << i)) needed[i] += x;
// trace(needed); dbg("\n");
bool can = true;
for (int i = 0; i < BITS - 1; i++) {
if (tmpa[i] < needed[i]) {
can = false;
break;
}
int remainder = tmpa[i] - needed[i];
int to_give = remainder / 2;
tmpa[i+1] += to_give;
tmpa[i] -= to_give * 2;
}
if (can) {
ans++;
dbg("sum is "); dbg(sum); dbg("\n");
}
}
return ans;
}
# | 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... |