This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// moreflags=grader.cpp
// naive solution (penultimate subtask)
// ... I think that code is fast enough? No?
#include "biscuits.h"
#include<cstdint>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iostream>
long long count_tastiness(long long x, std::vector<long long> a) {
std::vector<int64_t> all{a[0]};
int64_t s=0;
for(int i=0; i<(int)a.size()-1; ++i){
/*
for(auto y: all) std::cout<<((y-s)>>std::min(i, 62))<<' ';
std::cout<<" << \n";
*/
// optional subtract x
if(all[0]-(double)x*std::round(std::pow(2., i))>=(double)s){
// ^ check to avoid x<<i overflows int64_t (which is actually what happened to me in the contest)
for(int n=(int)all.size(), index=0; index<n;++index)
if(
all[index]-(x<<i)
>=s
)
all.push_back(all[index]-(x<<i));
else break;
}
s-=a[i+1]<<(i+1);
}
int curQuotient=0;
int64_t result{};
std::for_each(all.rbegin(), all.rend(), [&](auto y){
auto const val=(y-s)>>(a.size()-1);
while((curQuotient+1)*x<=val) ++curQuotient;
result+=curQuotient+1;
});
return result;
}
# | 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... |