이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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... |