Submission #1368296

#TimeUsernameProblemLanguageResultExecution timeMemory
1368296avighnaRarest Insects (IOI22_insects)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>

void move_inside(int i);
void move_outside(int i);
int press_button();

using namespace std;

int min_cardinality(int N) {
  // if we limit the acceptor to 1, we're gonna get the first occurence of each element
  // this lets us count the number of elements

  // then, if we pass again and limit the acceptor to 2, we get the first and second occurences
  // of each element

  // eventually, we'll get to a point where x occurences will not have x * <num in first>
  // this is when an element only has < x occurences

  vector<int> firsts;
  for (int i = 0; i < N; ++i) {
    move_inside(i);
    firsts.push_back(i);
    if (press_button() == 2) {
      move_outside(i);
      firsts.pop_back();
    }
  }
  int num_elems = firsts.size();
  for (int &i : firsts) {
    move_outside(i);
  }

  int x = *ranges::partition_point(views::iota(1, N), [&](int x) {
    vector<int> v;
    for (int i = 0; i < N; ++i) {
      move_inside(i);
      v.push_back(i);
      if (press_button() == x) {
        move_outside(i);
        v.pop_back();
      }
    }
    for (int &i : v) {
      move_outside(i);
    }
    return int(v.size()) == x * num_elems;
  });
  return x;
}

#ifdef MACOS_LOCAL
#include "stub.cpp"
#endif
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...