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"
#ifdef NYAOWO
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;
const int MAXK = 60;
int a[MAXK + 10];
int val[MAXK + 10];
struct Ayaya {
int l, r, add;
};
vector<Ayaya> aya;
int eval(int i) {
int res = 0;
Forr(it, sz(aya) - 1, 0) {
auto &ay = aya[it];
if(ay.l <= i && i <= ay.r) {
i -= ay.l;
res += ay.add;
}
}
return res;
}
long long count_tastiness(long long x, std::vector<long long> _a) {
int k = sz(_a);
memset(a, 0, sizeof(a));
memset(val, 0, sizeof(val));
aya.clear();
For(i, 0, k - 1) {
a[i] = _a[i];
val[i] = a[i] << i;
}
k = 60;
For(i, 1, k) {
val[i] += val[i - 1];
}
int lim = val[k] / x;
aya.push_back({0, 0, val[k]});
For(i, 0, k - 1) {
if((1ll << i) > lim) break;
int hi = aya.back().r + 1;
int lo = -1;
while(hi - lo > 1) {
int mi = (hi + lo) / 2;
int y = eval(mi);
if(val[k] - y + (x << i) <= val[i]) lo = mi;
else hi = mi;
}
if(lo >= 0) aya.push_back({aya.back().r + 1, aya.back().r + lo + 1, -(x << i)});
}
return aya.back().r + 1;
}
# | 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... |