Submission #436561

#TimeUsernameProblemLanguageResultExecution timeMemory
436561yuto1115Packing Biscuits (IOI20_biscuits)C++17
33 / 100
1096 ms5172 KiB
#include "biscuits.h" #include "bits/stdc++.h" #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++) #define rrep(i, n) for(ll i = ll(n)-1; i >= 0; i--) #define pb push_back #define eb emplace_back #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>; using vp = vector<P>; using vvp = vector<vp>; using vb = vector<bool>; using vvb = vector<vb>; using vs = vector<string>; template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll count_tastiness(ll x, vl a) { int k = 60; while ((int) a.size() < k) a.pb(0); if (x <= 10000) { rep(i, k) { if (a[i] > x) { ll l = (a[i] - x) / 2; a[i] -= l * 2; a[i + 1] += l; } } int mx = x + 10; vvl dp(k + 1, vl(mx)); dp[0][0] = 1; rep(i, k) rep(j, mx) { ll now = dp[i][j]; if (!now) continue; dp[i + 1][(j + a[i]) / 2] += now; if (j + a[i] >= x) dp[i + 1][(j + a[i] - x) / 2] += now; } rep2(i, 1, mx) assert(dp[k][i] == 0); return dp[k][0]; } else { vl lim(k); lim[0] = a[0]; rep(i, k - 1) lim[i + 1] = lim[i] / 2 + a[i + 1]; rep(i, k) lim[i] -= x; vi hold; rep(i, k) if (lim[i] >= 0) hold.pb(i); vvl sum(k); using T = tuple<ll, ll, int>; vector ls(k, vector<vector<T>>(k)); rep(i, k) { ll now = 0; rrep(j, i + 1) { now += a[j] >> (i - j); sum[i].pb(now); } rep(j, i + 1) { ll S = 0; ll p2 = 1; for (int l = i; l >= j; l--) { S *= 2; ls[i][j].eb((lim[l] + S) / (1LL << (i - l)), S, l); S += a[l]; p2 <<= 1; } sort(rall(ls[i][j])); } } ll ans = 0; auto dfs = [&](auto &dfs, int i, ll j) -> void { ans++; if (i < 0) return; // int it = lower_bound(all(sum[i]), j) - sum[i].begin(); // it = i - 1 - it; // for (int ni : hold) { // if (ni > it) break; // dfs(dfs, ni - 1, max(x - a[ni], 0LL) * 2); // } // it++; // chmax(it, 0); int it = 0; for (auto[check, S, ni] : ls[i][it]) { if (check < j) break; dfs(dfs, ni - 1, max((j << (i - ni)) - S + x - a[ni], 0LL) * 2); } }; dfs(dfs, k - 1, 0); 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...