제출 #1237167

#제출 시각아이디문제언어결과실행 시간메모리
1237167rxlfd314드문 곤충 (IOI22_insects)C++20
99.89 / 100
15 ms436 KiB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ari2 = array<int, 2>;
using ari3 = array<int, 3>;
using arl2 = array<ll, 2>;
using arl3 = array<ll, 3>;
template <class T> using vt = vector<T>;
#define all(x) begin(x), end(x)
#define size(x) (int((x).size()))
#define REP(a,b,c,d) for(int a=(b);(d)>0?a<=(c):a>=(c);a+=(d))
#define FOR(a,b,c) REP(a,b,c,1)
#define ROF(a,b,c) REP(a,b,c,-1)

int min_cardinality(int N) {
  vt<int> A, B;
  FOR(i, 0, N-1) {
    move_inside(i);
    if (!size(A) || press_button() == 1) {
      A.push_back(i);
    } else {
      move_outside(i);
      B.push_back(i);
    }
  }
  int cur = size(A), cnt = size(A);
  int lo = 1, hi = N / size(A);
  while (lo < hi) {
    const int mid = lo + hi + 1 >> 1;
    const int bef = cur;
    set<int> C;
    for (const auto &i : B) {
      move_inside(i);
      const int v = press_button();
      if (cur < mid || v <= mid)
        C.insert(i), cnt++;
      else
        move_outside(i);
      cur = v;
    }
    if (cnt == mid * size(A)) {
      lo = mid;
      vt<int> new_b;
      if (lo < hi)
        for (const auto &i : B)
          if (!C.count(i))
            new_b.push_back(i);
      B = new_b;
    } else {
      hi = mid - 1;
      cur = bef;
      cnt -= size(C);
      if (lo < hi)
        for (const auto &i : C)
          move_outside(i);
      B = vt<int>(all(C));
    }
  }
  return lo;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...