Submission #660386

#TimeUsernameProblemLanguageResultExecution timeMemory
660386evenvaluePacking Biscuits (IOI20_biscuits)C++17
0 / 100
1138 ms1051024 KiB
#include "biscuits.h" #include <bits/stdc++.h> using namespace std; template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template<typename T> using max_heap = priority_queue<T, vector<T>, less<T>>; using int64 = long long; using ld = long double; constexpr int kInf = 1e9 + 10; constexpr int64 kInf64 = 1e15 + 10; constexpr int kMod = 1e9 + 7; string to_bin(const int64 y, const int kBits = 20) { string ans; for (int bit = 0; bit < kBits; bit++) { ans += (y & (1LL << bit)) ? '1' : '0'; } return ans; } int64 count_tastiness(int64 x, vector<int64> a) { const int n = a.size(); int64 total = 0; for (int i = 0; i < n; i++) { total += (a[i] << i); } const int kBits = floor(log2(total) + 2); while (a.back() == 0) a.pop_back(); while (a.size() < kBits) a.push_back(0); const int64 ymax = total / x; auto check = [&](vector<int64> &biscuits, const string &y) -> bool { int64 need = 0; for (int i = y.size() - 1; i >= 0; i--) { if (y[i] == '1') need++; const int64 dec = min(need, biscuits[i]); biscuits[i] -= dec; need -= dec; need *= 2; } return not need; }; int64 ans = 0; for (int y = 0; y <= ymax; y++) { auto biscuits = a; const string bin = to_bin(y); bool flag = true; for (int bag = 0; bag < x; bag++) { flag &= check(biscuits, bin); } ans += flag; } return ans; }

Compilation message (stderr)

biscuits.cpp: In function 'int64 count_tastiness(int64, std::vector<long long int>)':
biscuits.cpp:36:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   36 |   while (a.size() < kBits) 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...