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 diff = 0, prevPress = 0;
vector<bool> mark;
void countDiff(int N) {
for (int i = 0; i < N; i++) {
move_inside(i);
if (press_button() == 1) {
diff++;
mark[i] = true;
} else
move_outside(i);
}
}
bool check(int lim, int N) {
if (prevPress > lim) {
for (int i = 0; i < N; i++)
if (mark[i]) {
mark[i] = false;
move_outside(i);
}
}
int cnt = accumulate(mark.begin(), mark.end(), 0);
for (int i = 0; i < N; i++)
if (!mark[i]) {
move_inside(i);
int tmp = press_button();
if (tmp > lim)
move_outside(i);
else {
prevPress = tmp;
cnt++;
mark[i] = true;
if (cnt == lim * diff)
break;
}
}
return cnt < lim * diff;
}
int min_cardinality(int N) {
mark.resize(N);
countDiff(N);
prevPress = diff;
int l = 2, r = N / diff, rs = 1;
while (l <= r) {
int mid = l + (r - l) / 5;
if (check(mid, N))
r = mid - 1;
else {
rs = mid;
l = mid + 1;
}
}
return rs;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |