Submission #1330145

#TimeUsernameProblemLanguageResultExecution timeMemory
1330145SpyrosAlivRarest Insects (IOI22_insects)C++20
0 / 100
15 ms428 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;
}

void dbg(vector<int> a) {
  cout << "DBG: ";
  for (auto x: a) cout << x << " ";
  cout << "\n";
}

int min_cardinality(int N) {
  n = N;
  ins.assign(n, false);
  vector<bool> ok(n, false);
  int types = 0;
  vector<int> cands;
  for (int i = 0; i < n; i++) {
    add(i);
    int x = press_button();
    if (x > 1) {
      rem(i);
    }
    else {
      types++;
      cands.push_back(i);
      ok[i] = true;
    }
  }
  if (types == 1) {
    return n;
  }
  vector<int> cnt(types, 1);
  if (types * types < n) {
    for (int i = 0; i < types; i++) {
      rem(cands[i]);
    }
    for (int i = 0; i < n; i++) {
      if (ok[i]) continue;
      int lo = 0, hi = types-1;
      int finIdx = -1;
      while (lo <= hi) {
        int mid = (lo + hi) / 2;
        for (int j = 0; j <= mid; j++) {
          add(cands[j]);
        }
        add(i);
        int tot = press_button();
        //dbg({i, tot});
        if (tot == 2) {
          hi = mid-1;
          finIdx = cands[mid];
        }
        else {
          lo = mid+1;
          assert(tot == 1);
        }
        for (int j = 0; j <= mid; j++) {
          rem(cands[j]);
        }
        rem(i);
      }
      cnt[finIdx]++;
    }
    int ans = cnt[0];
    for (int i = 1; i < types; i++) ans = min(ans, cnt[i]);
    return ans;
  }
  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;
    //dbg({mid, should});
    if (haveIn < should) {
      hi = mid-1;
    }
    else {
      fin = mid;
      lo = mid+1;
    }
  }
  return fin;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...