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;
long long b[65];
long long count_tastiness(long long x, std::vector<long long> a) {
long long S = 0;
int k = (int)a.size();
for(int i = 0; i < k; i ++){
S += (a[i]<<i);
}
if(x == 1){
for(int i = 0; i < k; i ++){
b[i] = a[i];
}
long long ans2 = 1;
long long val = 0;
long long mult = 1;
long long divider = 1;
for(int i = 0; i < k; i ++){
val += a[i]*mult;
if(val >= x*(2*mult/divider - 1)*divider ){
}else{
ans2 *= 1+(val/divider);
val = 0;
divider = mult*2;
}
mult <<= 1;
}
ans2 *= 1+(val/divider);
//printf("ans2=%lld\n", ans2);
//assert(ans == ans2);
return ans2;
}
long long ans = 1;
for(long long y = 1; y <= S/x;){
bool boleh = true;
for(int j = 0; j < k; j ++){
b[j] = a[j];
}
for(long long i = 0; i < x; i ++){
long long rem = y;
for(int j = k-1; j >= 0; j --){
long long quotient = min(rem>>j, b[j]);
b[j] -= quotient;
rem -= (quotient << j);
}
if(rem != 0){
boleh = false;
break;
}
}
if(boleh){
//printf("y=%lld works\n", y);
y ++;
}else{
long long lsb = y&(-y);
y += lsb;
y = y/lsb*lsb;
}
ans += boleh;
}
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... |