Submission #622818

#TimeUsernameProblemLanguageResultExecution timeMemory
622818ereklePacking Biscuits (IOI20_biscuits)C++17
9 / 100
1091 ms340 KiB
#include "biscuits.h" #include <bits/stdc++.h> using namespace std; const int MX = 60; long long count_tastiness(long long x, vector<long long> a) { int k = a.size(); long long maxSum = 0; for (int i = 0; i < k; ++i) { maxSum += (1LL << i) * a[i]; } k = 1; long long p = 1; while (p < maxSum) ++k, p <<= 1; while (a.size() < k) a.push_back(0); auto possible = [&k, &a, &maxSum, &x](const bitset<MX> &y) { long long need = 0; // as a multiple of current power of two for (int i = k-1; i >= 0; --i) { if (y[i]) need += x; long long use = min(need, a[i]); need -= use; need <<= 1; if (need > maxSum) return false; } return !need; }; bitset<MX> y = 0; long long ans = 1; bool foundNext = true; while (foundNext) { foundNext = false; bitset<MX> z = y; // find next highest y-value that works for (int i = 0; i < k; ++i) { if (y[i]) {z[i] = 0; continue;} // change a 0 into a 1, and set all smaller bits to 0 z[i] = 1; if (possible(z)) { ++ans, y = z; foundNext = true; break; } z[i] = 0; } } return ans; }

Compilation message (stderr)

biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:17:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |  while (a.size() < k) a.push_back(0);
      |         ~~~~~~~~~^~~
#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...