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>
using namespace std;
#define int long long
int cn[65], sum[65], x;
int solve(int R, int Bit) {
R = min(R, min((1ll << (Bit + 1)) - 1, sum[Bit] / x));
if(R < (1ll << Bit)) return 0;
if(R == (1ll << Bit)) return 1;
int B = __lg(R - (1ll << Bit));
return solve(R - (1ll << Bit), B) + (B == 0 ? 1ll : cn[B - 1]);
}
long long count_tastiness(long long X, std::vector<long long> a) {
x = X;
while(a.size() < 60) a.push_back(0);
for(int i = 0; i <= 59; i++) {
sum[i] = (1ll << i) * a[i];
if(i) sum[i] += sum[i - 1];
if(i) cn[i] = cn[i - 1];
else cn[i] = 1;
cn[i] += solve((1ll << (i + 1)) - 1, i);
}
return cn[59];
}
# | 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... |