#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();
vector<int> possible;
for (int i = 0; i < n; i++) {
possible.push_back(i);
}
auto Check = [&](int mid) {
vector<int> tmp;
for (int id = 0; id < (int) possible.size(); id++) {
int i = possible[id];
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;
}
swap(possible, roots);
for (int i = 0; i < (int) tmp.size(); i++) {
roots.pop_back();
in[tmp[i]] = false;
move_outside(tmp[i]);
}
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 |
1 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 |
3 ms |
208 KB |
Output is correct |
9 |
Incorrect |
4 ms |
256 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 |
1 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 |
3 ms |
208 KB |
Output is correct |
9 |
Incorrect |
4 ms |
256 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 |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
13 ms |
208 KB |
Output is correct |
8 |
Correct |
7 ms |
208 KB |
Output is correct |
9 |
Correct |
40 ms |
304 KB |
Output is correct |
10 |
Partially correct |
42 ms |
316 KB |
Output is partially correct |
11 |
Partially correct |
90 ms |
300 KB |
Output is partially correct |
12 |
Correct |
26 ms |
308 KB |
Output is correct |
13 |
Incorrect |
61 ms |
208 KB |
Wrong answer. |
14 |
Halted |
0 ms |
0 KB |
- |