# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1113727 | db_123 | Rarest Insects (IOI22_insects) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "insects.h"
#include <vector>
#include <set>
#include <unordered_map>
int n;
void check(int N, int d, int &always_add, int &rsBs, vector<bool> &vis) {
int mid = N / (2 * d);
if(mid == 0)
mid = 1;
vector<int> poz;
for (int i = 1; i <= n; i++) {
if (vis[i]) {
continue;
}
move_inside(i);
if (press_button() > mid) {
move_outside(i);
continue;
}
poz.emplace_back(i);
}
for (auto it : poz) {
move_outside(it);
}
if (poz.size() == mid * d) { /// e plin
for (auto it : poz) {
vis[it] = true;
}
always_add += poz.size() / d;
}
else if (poz.size() < mid * d) { /// nu e plin
rsBs = min(rsBs, mid);
int idx = 0;
for (int i = 1; i <= n; i++) {
if (vis[i]) {
continue;
}
while (idx < poz.size() && poz[idx] < i) {
idx ++;
}
if (poz[idx] != i) {
vis[i] = true;
}
}
}
return;
}
int min_cardinality(int N) {
vector<bool> vis(N + 1);
n = N;
int d = 0;
{
vector<int> temp;
for (int i = 1; i <= n; i++) {
move_inside(i);
if (press_button() > 1) {
move_outside(i);
continue;
}
temp.emplace_back(i);
}
d = temp.size();
for (auto it : temp) {
move_outside(it);
}
}
//cout << "d: " << d << '\n';
int always_add = 0, rsBs = 1e9;
while (N >= d) {
check(N, d, always_add, rsBs, vis);
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (vis[i]) {
continue;
}
cnt ++;
}
N = cnt;
}
return always_add;
}