Submission #1124206

#TimeUsernameProblemLanguageResultExecution timeMemory
1124206epicci23Rarest Insects (IOI22_insects)C++17
0 / 100
1 ms412 KiB
#include "insects.h"
#include "bits/stdc++.h"
using namespace std;

const int N = 2e3 + 5;

int vis[N],D,tot;

inline bool Add(int x){
  if(vis[x]) return 0;
  vis[x]=1;
  tot++;
  move_inside(x);
  return 1;
}

inline bool Rem(int x){
  if(!vis[x]) return 0;
  vis[x]=0;
  tot--;
  move_outside(x);
  return 1;
}

inline int Get(){
  return press_button();
}

int min_cardinality(int n){
  for(int i=0;i<n;i++){
    Add(i);
    if(i && Get() == 1) continue;
    Rem(i);
  }

  D = tot;
  if(D > n / 2) return 1;
  if(D == 1) return n;
  for(int i = 0; i < n; i++) Rem(i);

  int _n = n, l = 1 , r = n / D;
  while(l < r){
    int B = (l + r + 1) / 2;
    int X = _n / D;
    vector<int> L;
    for(int i = 0 ; i < n ; i++){
      if(Add(i)) L.push_back(i);
      if(i >= B && Get() > B) L.pop_back() , Rem(i);
    }
    if(X * D == tot) return X;
    _n = tot;
    if(tot == B * D){
      l = B;
    }
    else{
      for(int x : L) Rem(x);
      r = B - 1;
    }
  }

  return l;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...