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;
bool check(long long x, long long y, std::vector<long long> a) {
int k = a.size();
for(int i=0; i<x; i++) {
long long w = y;
for(int j=k-1; j>=0; j--) {
long long nd = w / (1ll << j);
nd = min(nd, a[j]);
a[j] -= nd;
w -= nd * (1ll << j);
}
if(w) return 0;
}
return 1;
}
long long count_tastiness(long long x, std::vector<long long> a) {
long long nxt = -1;
long long mul = 1;
long long ans = 1;
int it = 0;
while(1) {
nxt++;
//cout << ans << ' ' << mul << ' ' << nxt << "\n";
if(!check(x, nxt * mul, a)) { // find next perfect power, e.g. 6 -> 8
long long lg = 64 - __builtin_clzll(nxt) - 1;
lg = mul * (1ll << (lg + 1));
mul = lg;
// if [0, 9] ok, 10 not ok, ans *= nxt
if(nxt == 1) break;
ans *= nxt;
nxt = 0;
}
it++;
if(it > 30) break;
}
ans *= nxt;
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... |