#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);
if ((int) roots.size() == 1) {
return n;
}
int base = (int) roots.size();
auto Check = [&](int mid) {
vector<int> tmp;
for (int i = 0; i < n; i++) {
if (in[i]) {
continue;
}
move_inside(i);
if (press_button() > mid) {
move_outside(i);
} else {
tmp.push_back(i);
roots.push_back(i);
in[i] = true;
}
}
if ((int) roots.size() == base * mid) {
return true;
}
for (int i = 0; i < (int) tmp.size(); i++) {
roots.pop_back();
in[tmp[i]] = false;
}
return false;
};
int low = 2;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
208 KB |
Output is correct |
9 |
Incorrect |
6 ms |
296 KB |
Wrong answer. |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
208 KB |
Output is correct |
9 |
Incorrect |
6 ms |
296 KB |
Wrong answer. |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
12 ms |
208 KB |
Output is correct |
8 |
Correct |
15 ms |
320 KB |
Output is correct |
9 |
Correct |
33 ms |
208 KB |
Output is correct |
10 |
Partially correct |
35 ms |
304 KB |
Output is partially correct |
11 |
Partially correct |
147 ms |
208 KB |
Output is partially correct |
12 |
Correct |
20 ms |
308 KB |
Output is correct |
13 |
Partially correct |
124 ms |
292 KB |
Output is partially correct |
14 |
Partially correct |
66 ms |
300 KB |
Output is partially correct |
15 |
Incorrect |
45 ms |
304 KB |
Wrong answer. |
16 |
Halted |
0 ms |
0 KB |
- |