#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
using ll = long long;
int in[2020];
int min_cardinality(int n) {
int type = 0;
for (int i = 0;i < n;i++) {
move_inside(i);
if (press_button() == 2) {
move_outside(i);
}
else in[i] = 1, type++;
}
// for (int i = 0;i < n;i++) {
// if (!in[i]) move_inside(i), in[i] = 2;
// }
// int mxtype = press_button();
// for (int i = 0;i < n;i++) if (in[i] == 2) move_outside(i), in[i] = 0;
if (type == 1) return n;
int mxans = n / type;
int sq = sqrt(n);
if (type >= sq) {
int l = 1, r = mxans;
while (l < r) {
int mid = (l + r + 1) / 2;
int sz = mid - l;
int cnt = 0;
for (int i = 0;i < n;i++) {
if (in[i]) continue;
move_inside(i);
if (press_button() > mid) {
move_outside(i);
}
else in[i] = mid, cnt++;
}
if (cnt < type * sz) {
r = mid - 1;
for (int i = 0;i < n;i++) if (in[i] == mid) move_outside(i), in[i] = 0;
}
else l = mid;
}
return l;
}
else {
for (int i = 0;i < n;i++) if (!in[i]) move_inside(i);
for (int i = 0;i < n;i++) in[i] = 0;
int l = 1, r = press_button();
int idx = 1;
while (l < r) {
int mid = (l + r) / 2;
int sz = r - mid;
int cnt = 0;
idx++;
for (int i = 0;i < n;i++) {
if (in[i]) continue;
move_outside(i);
if (press_button() < mid) {
move_inside(i);
}
else cnt++, in[i] = idx;
if (cnt == type * sz) break;
}
if (cnt == type * sz) {
l = mid + 1;
for (int i = 0;i < n;i++) if (in[i] == idx) move_inside(i), in[i] = 0;
}
else r = mid;
}
return l - 1;
}
// n , n , n
/*
ans <= n / type
ans <= n - mx
*/
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Incorrect |
2 ms |
344 KB |
Wrong answer. |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Incorrect |
2 ms |
344 KB |
Wrong answer. |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Wrong answer. |
7 |
Halted |
0 ms |
0 KB |
- |