| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 627937 | lunchbox | 드문 곤충 (IOI22_insects) | C++17 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector<int> vi;
#ifdef LOCAL
void move_inside(int i);
void move_outside(int i);
int press_button();
#endif
int min_cardinality(int n) {
  int c = 0;
  vi u, v, in(n), p(n);
  iota(p.begin(), p.end(), 0);
  for (int i = 0; i < n; i++) {
    move_inside(p[i]);
    if (press_button() == 1) {
      c++;
      in[i] = 1;
    } else {
      move_outside(p[i]);
      u.push_back(i);
    }
  }
  int low = 2, hi = n / c, sz = 0, ans = 1;
  while (low <= hi) {
    int t = (low + hi) / 2;
    v.clear();
    shuffle(u.begin(), u.end(), rng);
    for (int i : u) {
      if (in[i])
        continue;
      move_inside(p[i]);
      if (press_button() > t) {
        move_outside(p[i]);
        v.push_back(i);
      } else
        sz++;
    }
    if (c + sz == t * c) {
      fill(in.begin(), in.end(), 1);
      for (int i : v)
        in[i] = 0;
      ans = t;
      low = t + 1;
    } else {
      hi = t - 1;
      if (low <= hi) {
        for (int i : v)
          in[i] = 1;
        for (int i : u)
          if (!in[i]) {
            move_outside(p[i]);
            sz--;
          }
      }
    }
  }
  return ans;
}
