Submission #776322

#TimeUsernameProblemLanguageResultExecution timeMemory
776322GusterGoose27Rarest Insects (IOI22_insects)C++17
100 / 100
58 ms336 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 1e5; int min_cardinality(int n) { vector<int> perm(n); iota(perm.begin(), perm.end(), 0); mt19937 gen(chrono::steady_clock::now().time_since_epoch().count()); for (int i = 1; i < n; i++) swap(perm[i], perm[gen()%(i+1)]); vector<int> reps; vector<int> extra; move_inside(perm[0]); int num_inside = 1; for (int i = 1; i < n; i++) { move_inside(perm[i]); if (press_button() > 1) { move_outside(perm[i]); extra.push_back(perm[i]); } else { num_inside++; } } int k = num_inside; if (k == 1) return n; while (extra.size() >= k) { int s = (extra.size()/2+k-1)/k; int base = num_inside/k; vector<int> l, r; for (int i = 0; i < s; i++) { move_inside(extra[i]); l.push_back(extra[i]); } for (int i = s; i < extra.size(); i++) { move_inside(extra[i]); if (press_button() > s+base) { move_outside(extra[i]); r.push_back(extra[i]); } else { l.push_back(extra[i]); } } if (l.size() == s*k) { extra = r; num_inside += l.size(); } else { extra = l; for (int v: l) move_outside(v); } } return num_inside/k; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:30:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |  while (extra.size() >= k) {
      |         ~~~~~~~~~~~~~^~~~
insects.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   for (int i = s; i < extra.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
insects.cpp:48:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |   if (l.size() == s*k) {
      |       ~~~~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...