제출 #1330129

#제출 시각아이디문제언어결과실행 시간메모리
1330129SpyrosAlivRarest Insects (IOI22_insects)C++20
0 / 100
0 ms344 KiB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;

int n;
vector<bool> ins;

void rem(int i) {
  if (ins[i]) move_outside(i);
  ins[i] = false;
}

void add(int i) {
  if (!ins[i]) move_inside(i);
  ins[i] = true;
}

int min_cardinality(int N) {
  n = N;
  ins.assign(n, false);
  int types = 0;
  for (int i = 0; i < n; i++) {
    add(i);
    int x = press_button();
    if (x > 1) {
      rem(i);
    }
    else types++;
  }
  if (types == 1) {
    return n;
  }
  int lo = 1, hi = n / types;
  int fin = n / types + 1;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    for (int i = 0; i < n; i++) {
      rem(i);
    }
    int haveIn = 0;
    for (int i = 0; i < n; i++) {
      add(i);
      haveIn++;
      if (press_button() > mid) {
        rem(i);
        haveIn--;
      }
    }
    int should = types * mid;
    if (haveIn < should) {
      lo = mid+1;
    }
    else {
      assert(haveIn == should);
      fin = mid;
      break;
    }
  }
  return fin;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...