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 <bits/stdc++.h>
using namespace std;
using ll = long long;
int min_cardinality(int n) {
vector<bool> in(n);
for (int i = 0; i < n; i++) {
move_inside(i);
if (press_button() == 2) move_outside(i);
else in[i] = 1;
}
int type = 0;
for (int i = 0; i < n; i++) {
if (in[i]) {
type++;
in[i] = 0;
move_outside(i);
}
}
vector<bool> blocked(n);
int lo = 1, hi = n / type, add = 0;
while (lo < hi) {
int x = (lo + hi + 1) / 2, cnt = 0;
for (int i = 0; i < n; i++) {
if (blocked[i]) continue;
move_inside(i);
if (press_button() == x + 1) move_outside(i);
else in[i] = 1, cnt++;
}
for (int i = 0; i < n; i++) {
if (in[i]) {
in[i] = 0;
move_outside(i);
if (cnt == x * type) {
blocked[i] = 1;
}
}
}
if (cnt == x * type) lo = 1, hi -= x - 1, add += x - 1;
else hi = x - 1;
}
return lo + add;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |