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>
#define N 200005
using namespace std;
long long vals[N];
long long count_tastiness(long long x, vector<long long> a){
int k = a.size();
vector<long long> pre = a;
for(int i = 1;i<k;i++){
pre[i] = pre[i-1] + a[i] * (1ll<<i);
}
for(int i = 0;i<k;i++){
pre[i] /= x;
}
for(int i = k-2;i>=0;i--){
pre[i] = min(pre[i],pre[i+1]);
}
while(pre.size() < 60)
pre.push_back(pre.back());
vals[0] = 0;
long long sz = 1;
vector<long long> nums;
nums.push_back(sz);
for(int i = 0;i<60;i++){
long long l = -1,r = sz-1;
while(l < r){
//cout << l << " " << r << endl;
long long m = (l + r + 1)/2;
long long tmp = m + 1;
//cout << m << endl;
long long curval = 0;
for(int j = i-1;j>=0;j--){
if(tmp > nums[j]){
curval += (1ll<<j);
tmp -= nums[j];
}
}
//cout << curval << " " << pre[i] << endl;
if(curval + (1ll<<i) <= pre[i]){
l = m;
}
else r = m-1;
}
//cout << l << endl;
sz += l + 1;
// int tmp = sz;
// for(int j = 0;j<tmp;j++){
// if(vals[j] + (1ll<<i) <= pre[i]){
// vals[sz++] = vals[j] + (1ll<<i);
// }
// else break;
// }
nums.push_back(sz);
}
long long ans = sz;
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... |