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 <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int randint(int lb, int ub) {
return uniform_int_distribution<int>(lb, ub)(rng);
}
int min_cardinality(int N) {
int nbCC = 0;
vector<int> toProcess;
set<int> inside;
for (int i = 0; i < N; ++i) {
move_inside(i);
if (i and press_button() == 2)
move_outside(i), toProcess.push_back(i);
else
nbCC++, inside.insert(i);
}
if (nbCC == 1)
return N;
shuffle(toProcess.begin(), toProcess.end(), rng);
int lo = 1, up = N / nbCC;
while (lo < up) {
int mid = (lo + up + 1) / 2;
vector<int> popped;
vector<int> insideMachine;
vector<int> notProcessed;
for (int u : toProcess) {
if ((int)inside.size() == nbCC * mid) {
popped.push_back(u);
} else {
move_inside(u);
inside.insert(u);
if (press_button() > mid)
popped.push_back(u), move_outside(u), inside.erase(u);
else
insideMachine.push_back(u);
}
}
if ((int)popped.size() == N - mid * nbCC) {
toProcess = popped;
lo = mid;
} else {
for (int u : insideMachine)
move_outside(u), inside.erase(u);
toProcess = insideMachine;
for (int x : notProcessed)
toProcess.push_back(x);
N = toProcess.size() + inside.size();
up = mid - 1;
}
}
return lo;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |