# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
311606 | milisav | Packing Biscuits (IOI20_biscuits) | C++14 | 20 ms | 896 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<bits/stdc++.h>
#include "biscuits.h"
using namespace std;
long long count_tastiness(long long x, std::vector<long long> a) {
long long t[70];
long long psum[70];
long long deg[70];
int k=60;
while(a.size()<k) a.push_back(0);
for(long long i=0;i<k;i++) {
t[i]=0;
psum[i]=0;
deg[i]=(1ll<<i);
}
psum[0]=a[0];
for(int i=1;i<k;i++) psum[i]=psum[i-1]+a[i]*deg[i];
int mk=0;
long long ts=psum[k-1];
for(int i=0;i<k;i++) {
if(ts/x<deg[i]) {
t[i]=((i==0) ? 1 : t[i-1]);
continue;
}
if(i==0) {
if(a[i]>=x) t[i]=2;
else t[i]=1;
}
else {
if(a[i]>=x) t[i]=2*t[i-1];
else {
long long nec=(x-a[i])*deg[i];
long long tot=0;
for(int j=i-1;j>=0;j--) {
long long bd=min((psum[j]-nec)/x,deg[j+1]-1);
if(bd>=deg[j]) {
tot+=(j==0 ? 1 : t[j-1]);
nec=max(nec+(x-a[j])*deg[j],0ll);
}
else nec=max(nec-deg[j]*a[j],0ll);
}
t[i]=t[i-1]+tot+(nec==0);
}
}
}
return t[k-1];
}
/*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;
}*/
Compilation message (stderr)
# | 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... |