# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
802537 | I_Love_EliskaM_ | Packing Biscuits (IOI20_biscuits) | C++14 | 1080 ms | 1056 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;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
using ll = long long;
#define pi pair<int,int>
#define f first
#define s second
const int N=1e5+5;
bitset<N> bs;
ll p2(ll x, vector<ll> a) {
while (a.size()<=60) a.pb(0);
ll s=1;
int k=0;
while (k<60 && (a[k]==0 || s>=(1ll<<k))) {
s+=(a[k]<<k);
++k;
}
ll old=s;
ll s2=1;
for (int t=k; t<60; ++t) {
if (!a[t]) continue;
if (s2 >= (1ll<<(t-k))) {
s2+=(a[t]<<(t-k));
} else {
s=s2*old;
old=s;
s2=1;
k=t;
--t;
}
}
s=s2*old;
old=s;
s2=1;
return s;
}
#define int ll
ll f(ll x, vector<pi>&a, int i) {
if (i>=a.size()-1) return 1+(a[i].f/x);
if (a[i].f>=x) {
a[i+1].f+=(a[i].f-x)>>(a[i+1].s-a[i].s);
ll q1=f(x,a,i+1);
a[i+1].f-=(a[i].f-x)>>(a[i+1].s-a[i].s);
a[i+1].f+=(a[i].f)>>(a[i+1].s-a[i].s);
ll q2=f(x,a,i+1);
a[i+1].f-=(a[i].f)>>(a[i+1].s-a[i].s);
return q1+q2;
} else {
a[i+1].f+=(a[i].f)>>(a[i+1].s-a[i].s);
ll q=f(x,a,i+1);
a[i+1].f-=(a[i].f)>>(a[i+1].s-a[i].s);
return q;
}
}
ll count_tastiness(ll x, vector<ll> a) {
if (x==1) {
return p2(x,a);
}
vector<pi> v;
forn(i,a.size()) if (a[i]) v.pb({a[i],i});
return f(x,v,0);
}
#undef int
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... |