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

#TimeUsernameProblemLanguageResultExecution timeMemory
366204dolphingarlicPacking Biscuits (IOI20_biscuits)C++14
100 / 100
78 ms1388 KiB
#include "biscuits.h" #include <bits/stdc++.h> typedef long long ll; using namespace std; ll x, s[60]; map<ll, ll> dp; ll solve(ll n) { if (n <= 0) return 0; if (dp.count(n)) return dp[n]; for (int i = 0; i < 60; i++) if ((1ll << i + 1) >= n) return dp[n] = solve(1ll << i) + solve(min(n, 1 + s[i] / x) - (1ll << i)); } ll count_tastiness(ll x, vector<ll> a) { for (int i = 0; i < a.size(); i++) if (a[i] > x) { ll to_merge = ((a[i] - x) >> 1) << 1; if (to_merge) { if (i == a.size() - 1) a.push_back(to_merge >> 1); else a[i + 1] += (to_merge >> 1); } a[i] -= to_merge; } while (a.size() < 60) a.push_back(0); ::x = x; memset(s, 0, sizeof s); s[0] = a[0]; for (int i = 1; i < 60; i++) s[i] = s[i - 1] + (1ll << i) * a[i]; dp.clear(); dp[1] = 1; return solve(1ll << 60); }

Compilation message (stderr)

biscuits.cpp: In function 'll solve(ll)':
biscuits.cpp:13:45: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   13 |  for (int i = 0; i < 60; i++) if ((1ll << i + 1) >= n)
      |                                           ~~^~~
biscuits.cpp: In function 'll count_tastiness(ll, std::vector<long long int>)':
biscuits.cpp:18:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for (int i = 0; i < a.size(); i++) if (a[i] > x) {
      |                  ~~^~~~~~~~~~
biscuits.cpp:21:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |    if (i == a.size() - 1) a.push_back(to_merge >> 1);
      |        ~~^~~~~~~~~~~~~~~
biscuits.cpp:30:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   30 |     for (int i = 1; i < 60; i++)
      |     ^~~
biscuits.cpp:32:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   32 |  dp.clear();
      |  ^~
biscuits.cpp: In function 'll solve(ll)':
biscuits.cpp:15:1: warning: control reaches end of non-void function [-Wreturn-type]
   15 | }
      | ^
#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...