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 "biscuits.h"
#include <map>
#include <cassert>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = 1e18 + 177013;
const int MAXK = 61;
ll sm[MAXK];
map<ll, ll> mp;
ll get_ans(ll mxsm) {
if (mxsm == 0)
return 1;
int i = 0;
int cnt = 0;
while (true) {
i = 0;
while (1ll << (i + 1) <= mxsm)
++i;
if (mxsm <= sm[i]) {
break;
} else {
mxsm = sm[i];
}
assert(++cnt <= 100);
}
if (mxsm == 0)
return 1;
if (mp.find(mxsm) != mp.end())
return mp[mxsm];
ll t = get_ans((1ll << i) - 1) + get_ans(mxsm - (1ll << i));
mp[mxsm] = t;
return t;
}
ll count_tastiness(ll x, vector<ll> a) {
mp.clear();
int k = a.size();
for (int i = 0; i < MAXK; ++i)
sm[i] = 0;
for (int i = 0; i < k; ++i)
sm[i] = a[i] << i;
for (int i = 1; i < MAXK; ++i) {
sm[i] += sm[i - 1];
}
for (int i = 0; i < MAXK; ++i) {
sm[i] /= x;
}
return get_ans(INF);
}
# | 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... |