# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
424098 | Apiram | Packing Biscuits (IOI20_biscuits) | C++14 | 0 ms | 0 KiB |
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 count_tastiness(long long x, std::vector<long long> a) {
int64_t counts =1;
/*int64_t covered = 0;
for (int64_t i =0;i<n;++i){
int64_t temp = pow(2,i)*arr[i];
counts+=(covered - temp)/pow(2,i);
covered = max(covered,temp);
}*/
vector<int64_t>arr(60,0);
int64_t sum=0;
for (int64_t i =0;i<a.size();++i){arr[i]=a[i];sum+=1LL<<i;}
for (int64_t i =1;i<60;++i){
if (arr[i-1]>x){
arr[i]+=( arr[i-1] - x )/2;
arr[i-1] = x + arr[i-1]%2;
}
}
if(sum>1e5)sum=1e5;
for (int64_t i =1;i<=sum;++i){
int64_t temp =i;
int last =0;
vector<bool>needed(60,false);
int64_t minny=LLONG_MAX;
for (int64_t j = 60 ; j>=0;--j){
if ((1LL<<j) <= temp){
temp-=(1LL<<j);
needed[j]=true;
last=j;
}
if (!temp)break;
}
int64_t ones = 0;
bool ok=true;
for (int64_t j =0;j<60;++j){
if (j>last)break;
if (needed[j]){
if (arr[j]>=x)continue;
if ((x-arr[j])*(1LL<<j) > ones){
ok=false;break;
}
else {
ones-=(x-arr[j])*(1LL<<j);
}
}
else {
ones+=arr[j]<<j;}
}
counts+=ok;
}
return counts;
}
int main() {
int q;
assert(scanf("%d", &q) == 1);
vector<int> k(q);
vector<long long> x(q);
vector<vector<long long>> a(q);
vector<long long> results(q);
for (int t = 0; t < q; t++) {
assert(scanf("%d%lld", &k[t], &x[t]) == 2);
a[t] = vector<long long>(k[t]);
for (int i = 0; i < k[t]; i++) {
assert(scanf("%lld", &a[t][i]) == 1);
}
}
fclose(stdin);
for (int t = 0; t < q; t++) {
results[t] = count_tastiness(x[t], a[t]);
}
for (int t = 0; t < q; t++) {
printf("%lld\n", results[t]);
}
fclose(stdout);
return 0;
}