Submission #1029127

#TimeUsernameProblemLanguageResultExecution timeMemory
102912742kangarooRarest Insects (IOI22_insects)C++17
99.82 / 100
37 ms952 KiB
#include "insects.h" #include "bits/stdc++.h" using namespace std; int min_cardinality(int N) { int nums = 0; vector<int> inside, outside, aIn; vector<int> o(N); std::iota(o.begin(), o.end(),0); random_device dev; std::shuffle(o.begin(), o.end(), dev); for (int i = 0; i < N; ++i) { nums++; move_inside(o[i]); if (press_button() > 1) { if (i == N - 1) { aIn.push_back(o[i]); } else { outside.push_back(o[i]); move_outside(o[i]); } } else { if (i == N - 1) return 1; inside.push_back(o[i]); } } int k = inside.size(); int l = 1, r = N / k + 1; while (l + 1 < r) { int m = (l + r + 1) / 2; vector<int> nIn, nOut; for (auto e: outside) { if ((inside.size() + nIn.size() + aIn.size()) == m * k) { nOut.push_back(e); } else { nums++; move_inside(e); if (press_button() > m) { nOut.push_back(e); move_outside(e); } else nIn.push_back(e); } } if ((inside.size() + nIn.size() + aIn.size()) == m * k) { l = m; outside = nOut; inside.reserve(inside.size() + nIn.size() + aIn.size()); inside.insert(inside.end(), nIn.begin(), nIn.end()); inside.insert(inside.end(), aIn.begin(), aIn.end()); aIn.clear(); } else { r = min(m, (int)(inside.size() + nIn.size() + aIn.size())/k + 1); int nM = (l + r + 1) / 2 - l; nIn.reserve(nIn.size() + aIn.size()); nIn.insert(nIn.end(), aIn.begin(), aIn.end()); aIn.clear(); for (int i = 0; i < nM && !nIn.empty(); ++i) { aIn.push_back(nIn.back()); nIn.pop_back(); } for (auto e: nIn) { move_outside(e); } outside = nIn; } } //if ((double)nums/(double)N > 3) return 0; return l; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:34:50: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |    if ((inside.size() + nIn.size() + aIn.size()) == m * k) {
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
insects.cpp:45:49: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |   if ((inside.size() + nIn.size() + aIn.size()) == m * k) {
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...