# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
629751 | hltk | Rarest Insects (IOI22_insects) | C++17 | 262 ms | 476 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "insects.h"
#include <vector>
#include <random>
#include <algorithm>
#include <numeric>
using namespace std;
int min_cardinality(int n) {
vector<int> inds(n);
iota(inds.begin(), inds.end(), 0);
shuffle(inds.begin(), inds.end(), mt19937_64{});
int types = 0;
vector<int> x;
for (int i : inds) {
move_inside(i);
if (press_button() == 1) {
types++;
x.push_back(i);
} else {
move_outside(i);
}
}
if (types == 1 || types == n) {
return 1 ^ n ^ types;
}
auto test = [&](int k) {
vector<int> x;
for (int i : inds) {
move_inside(i);
if (press_button() > k) {
move_outside(i);
} else {
x.push_back(i);
}
if (x.size() == k * types) {
break;
}
}
for (int i : x) {
move_outside(i);
}
return x.size() != k * types;
};
int l = 1, r = n - 1;
while (l < r) {
int m = (l + r) / 2;
if (test(m + 1)) r = m;
else l = m + 1;
}
return l;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |