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 <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector<int> vi;
#ifdef LOCAL
void move_inside(int i);
void move_outside(int i);
int press_button();
#else
#include "insects.h"
#endif
int min_cardinality(int n) {
int c = 0;
vi in(n), p(n);
iota(p.begin(), p.end(), 0);
for (int i = 0; i < n; i++) {
move_inside(i);
if (press_button() == 1) {
c++;
in[i] = 1;
} else
move_outside(i);
}
int low = 2, hi = n / c, sz = 0, ans = 1;
while (low <= hi) {
int t = (low + hi) / 2;
vi v;
shuffle(p.begin(), p.end(), rng);
for (int i = 0; i < n; i++) {
if (in[p[i]])
continue;
move_inside(p[i]);
if (press_button() > t) {
move_outside(p[i]);
v.push_back(p[i]);
} else
sz++;
if (c + sz == t * c) {
for (int j = i + 1; j < n; j++)
if (!in[j])
v.push_back(p[j]);
break;
}
}
if (c + sz == t * c) {
fill(in.begin(), in.end(), 1);
for (int i : v)
in[i] = 0;
ans = t;
low = t + 1;
} else {
hi = t - 1;
if (low <= hi) {
for (int i : v)
in[i] = 1;
for (int i = 0; i < n; i++)
if (!in[i]) {
move_outside(i);
sz--;
}
}
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |