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 <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<ll> v;
vector<ll> k;
ll rec(int i, ll x) { // the last x are blocked, find total number of blocked
if(i < (int)k.size()) {
if(x <= k[i]) return v[i];
}
if(i == 0) {
if(v.size() == 0) return x;
if(x == 1) return x;
return v[i];
}
if(x < ((ll)1 << (i))) {
return v[i-1] + rec(i-1, x);
}
return ((ll)1 << (i)) + rec(i-1, x - ((ll)1 << (i)));
}
long long count_tastiness(long long x, std::vector<long long> a) {
vector<ll>().swap(v);
vector<ll>().swap(k);
ll tot = 0;
for(int i = 0; i < 61; i++) {
if(x * ((ll)1 << (i+1)) > (ll)2000000000000000000) break;
if(i == (int)a.size()) a.push_back(0);
tot += ((ll)1 << i)*a[i];
if(tot >= x*((ll)1 << (i+1)) - 1) {
v.push_back(rec(i, 0));
k.push_back(0);
}
else {
v.push_back(rec(i, ((ll)1 << (i+1)) - tot/x - 1));
k.push_back(((ll)1 << (i+1)) - tot/x - 1);
}
}
return ((ll)1 << v.size()) - v[v.size()-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... |