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 <algorithm>
using namespace std;
vector<int> v;
int inside = 0;
int min_cardinality(int n) {
int uniq = 0;
for (int i = 0; i < n; ++i) {
move_inside(i);
if (press_button() > 1) {
move_outside(i);
v.push_back(i);
} else uniq++;
}
if (uniq == 1) return n;
if (uniq > n / 2) return 1;
inside = uniq;
int ans = 1;
for (int k = 2 << 10; k >= 1; k /= 2) {
if (ans + k > n / 2) continue;
vector<int> in;
int mx = ans + k;
int gc = 0;
for (int x : v) {
move_inside(x);
if (press_button() > mx) {
move_outside(x);
} else {
in.push_back(x);
gc++;
}
}
if ((inside + gc) / mx == uniq) {
ans += k;
inside += gc;
for (int x : in) v.erase(find(v.begin(), v.end(), x));
} else {
v = in;
for (int x : in) move_outside(x);
}
}
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... |