Submission #736531

#TimeUsernameProblemLanguageResultExecution timeMemory
736531AdamGSRarest Insects (IOI22_insects)C++17
82.17 / 100
138 ms456 KiB
#include "insects.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
int min_cardinality(int n) {
  vector<int>A, B;
  rep(i, n) {
    move_inside(i);
    if(press_button()==1) A.pb(i);
    else {
      B.pb(i);
      move_outside(i);
    }
  }
  for(auto i : A) move_outside(i);
  int po=1, ko=n/(int)A.size();
  stack<pair<int,int>>S;
  S.push({-1, -1});
  while(po<ko) {
    int sr=po+(ko-po)/4;
    while(S.top().st>sr) {
      B.pb(S.top().nd);
      move_outside(S.top().nd);
      S.pop();
    }
    vector<int>tmp;
    for(auto i : B) {
      move_inside(i);
      int x=press_button();
      if(x>sr) {
        move_outside(i);
        tmp.pb(i);
        continue;
      }
      S.push({x, i});
    }
    B=tmp;
    bool ok=false;
    for(auto i : A) {
      move_inside(i);
      int x=press_button();
      move_outside(i);
      if(x==sr) {
        ok=true;
        break;
      }
    }
    if(ok) ko=sr; else po=sr+1;
  }
  return po;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...