제출 #628884

#제출 시각아이디문제언어결과실행 시간메모리
628884600Mihnea드문 곤충 (IOI22_insects)C++17
45.46 / 100
271 ms560 KiB
#include "insects.h"
#include <bits/stdc++.h>

using namespace std;

set<int> s;

void add(int i) {
  assert(!s.count(i));
  s.insert(i);
  move_inside(i);
}

void del(int i) {
  assert(s.count(i));
  s.erase(i);
  move_outside(i);
}

int get() {
  return press_button();
}

int min_cardinality(int n) {
  int cnt_distinct = 0;
  for (int i = 0; i < n; i++) {
    add(i);
    if (get() == 1) {
      cnt_distinct++;
    } else {
      move_outside(i);
    }
  }
  while (!s.empty()) {
    del(*s.begin());
  }
  int low = 1, high = n, sol = -1;
  while (low <= high) {
    int mid = (low + high) / 2;
    while (!s.empty()) {
      del(*s.begin());
    }
    for (int i = 0; i < n; i++) {
      add(i);
      if (get() > mid) {
        del(i);
      }
    }
    if ((int) s.size() == mid * cnt_distinct) {
      sol = mid;
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  assert(sol != -1);
  return sol;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...