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;
int types = 0, ch[2020], use[2020], cnt = 0;
int min_cardinality(int N) {
// calculate types: N times
for (int i = 0; i < N; i++) {
move_inside(i);
if (press_button() >= 2) move_outside(i);
else {
ch[i] = 1;
types++;
cnt++;
use[i] = 1;
}
}
int st = 1, ed = N / types;
bool add = true;
while (st < ed) {
int x = (st + ed + 1) / 2;
if (add) {
for (int i = 0; i < N; i++) {
if (ch[i] == 1) continue;
if (use[i] == 1) continue;
move_inside(i);
if (press_button() > x) move_outside(i);
else {
use[i] = 1;
cnt++;
}
}
}
else {
for (int i = N - 1; i >= 0; i--) {
if (ch[i] == 1) continue;
if (use[i] == 0) continue;
move_outside(i);
if (press_button() < x) move_inside(i);
else {
use[i] = 0;
cnt--;
}
}
for (int i = 0; i < N; i++) {
if (ch[i] == 1) continue;
if (use[i] == 1) continue;
move_inside(i);
if (press_button() > x) move_outside(i);
else {
use[i] = 1;
cnt++;
}
}
}
if (cnt == x * types) {
st = x;
add = true;
for (int i = 0; i < N; i++) if (use[i] == 1) ch[i] = 1;
}
else {
ed = x - 1;
add = false;
for (int i = 0; i < N; i++) if (use[i] == 0) ch[i] = 1;
}
}
return st;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |