#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#include "insects.h"
using namespace std;
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
int min_cardinality(int N) {
vector<int> idx(N);
iota(all(idx), 0);
shuffle(all(idx), mt19937(1498371));
vector<int> groups{idx[0]};
move_inside(idx[0]);
for (int i = 1; i < N; i++) {
move_inside(idx[i]);
if (press_button() > 1) move_outside(idx[i]);
else groups.push_back(idx[i]);
}
for (int x : groups) move_outside(x);
int ans = 1e9;
auto solve = [&](auto&& s, vector<int> v, vector<int> pot) -> void {
if (sz(v) == 1) {
ckmin(ans, sz(pot)); return;
}
int l = 2, r = sz(pot) / sz(v), ans2 = 1;
vector<int> got = groups;
while (l <= r) {
int mid = (l+r)/2;
for (int x : pot) {
if (find(all(got), x) != got.end()) {
continue;
}
move_inside(x);
if (press_button() > mid) move_outside(x);
else got.push_back(x);
}
if (sz(got) == mid * sz(v)) {
ans2 = mid, l = mid+1;
}
else {
r = mid-1;
for (int x : got) move_outside(x);
swap(pot, got);
got.clear();
}
}
ckmin(ans, ans2);
};
solve(solve, groups, idx);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
0 ms |
344 KB |
Wrong answer. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
0 ms |
344 KB |
Wrong answer. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Wrong answer. |
2 |
Halted |
0 ms |
0 KB |
- |