#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define en cout << '\n'
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
const int N = 1e5+10;
int last_pres = 0;
int press_buttoon(){
  return last_pres = press_button();
}
int min_cardinality(int n) {
  vi v, u;
  for(int i = 0; i < n; ++i){
    move_inside(i);
    int val = press_button();
    if(val > 1){
      move_outside(i);
      u.pb(i);
    }else{
      v.pb(i);
    }
    // u.pb(i);
  }
  // for(int x: v) move_outside(x);
  int sz = v.size();
  if(sz <= 3){
    for(int x: v) move_outside(x);
    vector<int> tp(n, -1);
    for(int j = 0; j < v.size(); ++j) tp[v[j]] = j;
    for(int i = 0; i < n; ++i){
      if(tp[i] != -1) continue;
      tp[i] = 0;
      move_inside(i);
      for(int j = 1; j < v.size(); ++j){
        move_inside(v[j]);
        if(press_button() == 2){
          tp[i] = j;
          move_outside(v[j]);
          break;
        }
        move_outside(v[j]);
      }
      move_outside(i);
    }
    array<int, 3> res = {0};
    for(int x: tp) res[x]++;
    int ans = 1e9;
    for(int j = 0; j < sz; ++j) ans = min(ans, res[j]);
    return ans;
  }
  // v.clear();
  last_pres = 1;
  int l = 2, r = n / sz, ans = 1;
  int inside = sz;
  while(l <= r){
    int mid = l+r>>1;
    // u is the cur search set, v is the inside set.
    if(last_pres <= mid){
      // we gotta add new ones from u.
      // the ones in v are fixed.
      v.clear();
      vi U;
      for(int x: u){
        move_inside(x);
        if(press_buttoon() <= mid){
          v.pb(x);
          ++inside;
        }else{
          move_outside(x);
          U.pb(x);
        }
      }
      u = U;
    }else{
      // we gotta erase some from v.
      u.clear();
      for(int x: v) move_outside(x), --inside;
      vi V;
      for(int x: v){
        move_inside(x);
        if(press_buttoon() <= mid){
          V.pb(x);
          ++inside;
        }else{
          u.pb(x);
          move_outside(x);
        }
      }
      v = V;
    }
    // cerr << l << ' ' << r << " :\n";
    // for(int x: v) cerr << x << ' ';  cerr << '\n';
    // for(int x: u) cerr << x << ' ';  cerr << '\n';
    // cerr << '\n';
    if(inside == mid * sz){
      ans = mid;
      l = mid + 1;
    }else{
      r = mid - 1;
    }
  }
  return ans;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |