#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
int min_cardinality(int N) {
int n = N;
vector<int> in(n);
vector<int> roots;
for (int i = 0; i < n; i++) {
move_inside(i);
if (press_button() == 2) {
move_outside(i);
} else {
roots.push_back(i);
in[i] = true;
}
}
assert((int) roots.size() > 0);
auto get_low_bound = [&]() {
for (int i = 0; i < n; i++) {
if (in[i]) {
continue;
}
move_inside(i);
}
int big = press_button();
for (int i = 0; i < n; i++) {
if (in[i]) {
continue;
}
move_outside(i);
}
int low = 1, high = n / (int) roots.size();
auto Can = [&](int mid) {
int restant = n - (int) roots.size();
if ((restant + mid - 1) / mid > big) {
return false;
}
return true;
};
while (low <= high) {
int mid = low + (high - low) / 2;
if (Can(mid)) {
high = mid - 1;
} else {
low = mid + 1;
}
}
++high;
cerr << "ici " << high << '\n';
return high;
};
auto Check = [&](int mid) {
vector<int> cnt;
for (int i = 0; i < n; i++) {
if (in[i]) {
continue;
}
move_inside(i);
if (press_button() > mid) {
move_outside(i);
} else {
cnt.push_back(i);
}
}
for (int i = 0; i < (int) cnt.size(); i++) {
move_outside(cnt[i]);
}
if ((int) cnt.size() == (mid - 1) * (int) roots.size()) {
return true;
}
return false;
};
int low = get_low_bound();
int high = n / (int) roots.size();
while (low <= high) {
int mid = low + (high - low) / 2;
if (Check(mid)) {
low = mid + 1;
} else {
high = mid - 1;
}
}
--low;
return low;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
18 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
7 ms |
300 KB |
Output is correct |
9 |
Incorrect |
4 ms |
208 KB |
Wrong answer. |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
18 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
7 ms |
300 KB |
Output is correct |
9 |
Incorrect |
4 ms |
208 KB |
Wrong answer. |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Partially correct |
1 ms |
208 KB |
Output is partially correct |
7 |
Partially correct |
137 ms |
304 KB |
Output is partially correct |
8 |
Correct |
14 ms |
300 KB |
Output is correct |
9 |
Partially correct |
48 ms |
308 KB |
Output is partially correct |
10 |
Incorrect |
75 ms |
304 KB |
Wrong answer. |
11 |
Halted |
0 ms |
0 KB |
- |