제출 #1227179

#제출 시각아이디문제언어결과실행 시간메모리
1227179brinton드문 곤충 (IOI22_insects)C++20
47.50 / 100
59 ms428 KiB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
int min_cardinality(int N) {
  auto tryk = [&](int k){
    vector<int> cur;
    for(int i = 0;i < N;i++){
      move_inside(i);
      if(press_button() > k){
        move_outside(i);
      }else{
        cur.push_back(i);
      }
    }
    for(auto &i:cur) move_outside(i);
    return cur.size();
  };
  // first check group
  int gp = tryk(1);
  // binary search
  int bottom = 1;
  int top = N;
  int maxPossible = 1;
  // cout << "!" << gp << endl;
  while(bottom <= top){
    int mid = (bottom+top)/2;
    int respond = tryk(mid);
    // cout << bottom << " " << top << endl;
    // cout << "!" << mid << ":" << respond << endl;
    if(respond == gp*mid){
      maxPossible = max(maxPossible,mid);
      bottom = mid+1;
    }else{
      top = min(respond/gp,mid-1);
    }
  }
  // cout << bottom << " " << top << endl;
  return maxPossible;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...