#include "insects.h"
#include <bits/stdc++.h>
std::set <int> IN;
std::set <int> last;
void inside(int x) {
IN.insert(x);
}
void outside(int x) {
IN.erase(x);
}
int ask(int n) {
for (int i = 0; i < n; i++) {
if (IN.count(i) && !last.count(i)) {
move_inside(i);
} else if (!IN.count(i) && last.count(i)) {
move_outside(i);
}
}
static std::map <std::vector <int>, int> mem;
last = IN;
std::vector <int> tmp;
for (int x : IN) tmp.push_back(x);
auto it = mem.find(tmp);
if (it != mem.end()) return it->second;
return mem[tmp] = press_button();
// return press_button();
}
std::vector <int> invert(std::vector <int> v, int n) {
std::vector <int> u;
std::sort(v.begin(), v.end());
for (int i = 0, j = 0; i < n; i++) {
if (j < (int) v.size() && v[j] == i) {
j++;
continue;
}
u.push_back(i);
}
return u;
}
int min_cardinality(int n) {
std::vector <int> in, pool;
for (int i = 0; i < n; i++) {
inside(i);
in.push_back(i);
if (ask(n) == 1) continue;
outside(i);
in.pop_back();
pool.push_back(i);
}
int uniq = in.size();
int ans = n / uniq;
// srand(time(0));
for (int l = 1, r = n / uniq - 1; l <= r; ) {
int mid = (1 + l + r) >> 1;
in.clear();
std::vector <int> new_pool;
// std::random_shuffle(pool.begin(), pool.end());
for (int i : pool) {
inside(i);
in.push_back(i);
if ((int) IN.size() == uniq * mid + 1 || ask(n) > mid) {
outside(i);
in.pop_back();
new_pool.push_back(i);
continue;
}
}
pool = new_pool;
if ((int) IN.size() == uniq * mid) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
pool = in;
for (int x : in) {
outside(x);
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Wrong answer. |
2 |
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 |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Wrong answer. |
3 |
Halted |
0 ms |
0 KB |
- |