(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 #397594

#TimeUsernameProblemLanguageResultExecution timeMemory
397594qwerasdfzxclPacking Biscuits (IOI20_biscuits)C++14
100 / 100
187 ms1356 KiB
#include "biscuits.h" #include <bits/stdc++.h> typedef long long ll; using namespace std; vector<ll> A; ll X; map<ll, ll> calc(set<ll> &st, int k){ if (!k){ map<ll, ll> ret; ret[0] = 1; ret[1] = ret[0] + (A[0]>=X); return ret; } ll S = 0; for (int i=0;i<=k;i++) S += (1LL<<i)*A[i]; ll c = S/X, mx1 = (1LL<<k)-1; set<ll> tmp; if (c<(1LL<<(k+1))) tmp.insert(c&((1LL<<k)-1)); for (auto &val:st) tmp.insert(val&mx1); map<ll, ll> tmp2 = calc(tmp, k-1), ret; if (c<(1LL<<(k+1)) && c>mx1) ret[c] = tmp2[mx1]+tmp2[c&mx1]; else if (c<=mx1) ret[c] = tmp2[c]; for (auto &val:st){ if (val<=mx1) ret[val] = tmp2[val]; else if (val<=c){ ret[val] = tmp2[mx1]+tmp2[val&mx1]; } else ret[val] = ret[c]; } return ret; } long long count_tastiness(long long x, vector<long long> a) { A = a; X = x; ll S = 0; int k = (int)A.size()-1; for (;!A[k];k--); for (int i=0;i<=k;i++) S += (1LL<<i)*A[i]; //printf(" %d ", k); if (!k) return S/x+1; if (k<0) return 1; ll mx = (1LL<<k)-1, q = (A[k]-1)/x+1; ll sr = (S/x)&mx; set<ll> tmp; tmp.insert(mx); tmp.insert(sr); map<ll, ll> M = calc(tmp, k-1); //printf("%lld %lld\n", M[mx], M[sr]); ll ans = M[mx]*q; ans += ((S/x)/(1LL<<k)+1-q)*M[mx]; ans -= M[mx] - M[sr]; return ans; }
#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...