(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #436313

#TimeUsernameProblemLanguageResultExecution timeMemory
436313frodakcinPacking Biscuits (IOI20_biscuits)C++17
100 / 100
171 ms1328 KiB
#include "biscuits.h" #include <cstdio> using ll = long long; ll x; std::vector<ll> a; bool test(ll v) // O(K) { ll n=0; for(int i=0;v;v>>=1, n>>=1, ++i) { if(i<(int)a.size()) n+=a[i]; if(v&1) if((n-=x)<0) return 0; } return 1; } ll get(int b) // O(K^2) -- max, with b'th bit turned on { ll v=1ll<<b; for(int i=b-1;i>=0;--i) if(test(v|1ll<<i)) v|=1ll<<i; return v; } const int MX = 2e5; // idk, just smth large ll stv[MX]; int l[MX], r[MX], X; int nn(int p=0) { ++X; stv[X]=stv[p]; l[X]=l[p]; r[X]=r[p]; return X; } void up(int n) // do NOT call on leaves { stv[n]=stv[l[n]]+stv[r[n]]; } int pull(int n, ll nl, ll nr, ll ql, ll qr) { if(ql <= nl && nr <= qr) return n; if(nr-nl>1) { n = nn(n); ll m=nl+(nr-nl)/2; if(ql < m) l[n] = pull(l[n], nl, m, ql, qr); else l[n]=0; if(m < qr) r[n] = pull(r[n], m, nr, ql, qr); else r[n]=0; up(n); } return n; } long long count_tastiness(long long _x, std::vector<long long> _a) { x=_x; a=_a; X=0; int root=nn(); stv[root]=1; for(int i=0;;++i) { int nroot = nn(); l[nroot] = root; r[nroot] = 0; if(test(1ll<<i)) { ll bound = get(i); bound ^= 1ll<<i; r[nroot] = pull(root, 0, 1ll<<i, 0, bound+1); //printf("%d: %lld [%lld]\n", i, bound+1, stv[r[nroot]]); } else if(i>=(int)a.size()) break; root = nroot; up(root); //printf("%d: %lld\n", i, stv[root]); } return stv[root]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...