제출 #714104

#제출 시각아이디문제언어결과실행 시간메모리
714104PherokungRarest Insects (IOI22_insects)C++17
100 / 100
65 ms436 KiB
#include "insects.h"
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int min_cardinality(int n){
  vector<int> a(n);
  iota(a.begin(),a.end(),0);
  random_shuffle(a.begin(),a.end());

  int type = 0;
  vector<int> in,out,in_temp,out_temp;
  for(int i=0;i<n;i++){
    move_inside(a[i]);
    if(press_button() > 1) move_outside(a[i]), out.pb(a[i]);
    else type++, in.pb(a[i]);
  }
  int be = 1, ed = n/type;
  while(be <= ed){
    int mid = (be+ed)/2, cnt = in.size();
    in_temp.clear(), out_temp.clear();
    for(auto x : out){
      if(cnt == mid * type){
        out_temp.pb(x);
        continue;
      }
      move_inside(x);
      if(press_button() > mid) move_outside(x), out_temp.pb(x);
      else cnt++, in_temp.pb(x);
    }
    if(cnt == mid * type){
      be = mid+1;
      for(auto x : in_temp) in.pb(x);
      out = out_temp;
    }
    else{
      ed = mid-1;
      for(auto x : in_temp) move_outside(x);
      out = in_temp;
    }
  }
  return ed;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...