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

#TimeUsernameProblemLanguageResultExecution timeMemory
432821usachevd0Packing Biscuits (IOI20_biscuits)C++17
100 / 100
145 ms1320 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define all(a) (a).begin(), (a).end() #define Time (clock() * 1.0 / CLOCKS_PER_SEC) using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; using ld = long double; template<typename T1, typename T2> bool chkmin(T1& x, T2 y) { return y < x ? (x = y, true) : false; } template<typename T1, typename T2> bool chkmax(T1& x, T2 y) { return y > x ? (x = y, true) : false; } void debug_out() { cerr << endl; } template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cerr << ' ' << A; debug_out(B...); } template<typename T> void mdebug_out(T* a, int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n) #else #define debug(...) 1337 #define mdebug(a, n) 228 #endif template<typename T> ostream& operator << (ostream& stream, const vector<T>& v) { for (auto& e : v) stream << e << ' '; return stream; } template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) { return stream << p.first << ' ' << p.second; } ll count_tastiness(ll x, vector<ll> a) { int k = a.size(); vector<ll> s(k + 1, 0); for (int i = 0; i < k; ++i) s[i + 1] = s[i] + (a[i] << i); map<pli, ll> mem; function<ll(ll, int)> rec = [&](ll m, int i) { chkmin(m, s[i + 1] / x); if (m < 0) return 0LL; pli key = {m, i}; if (mem.count(key)) return mem[key]; if (m == 0 || i < 0) return mem[key] = 1; if (i == 0) { return mem[key] = min(a[0] / x, m) + 1; } ll block1 = m + 1; ll block2 = 1LL << i; return mem[key] = block1 / block2 * rec(block2 - 1, i - 1) + rec(block1 % block2 - 1, i - 1); }; rec(s[k] / x, k - 1); return rec(s[k], k - 1); } #ifdef LOCAL int32_t main() { #ifdef LOCAL freopen("in", "r", stdin); #endif ios::sync_with_stdio(0); cin.tie(0); 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; } #endif
#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...