Submission #659910

#TimeUsernameProblemLanguageResultExecution timeMemory
659910peijarRarest Insects (IOI22_insects)C++17
0 / 100
5 ms300 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; int min_cardinality(int N) { vector<int> roots; int nbCC = 0; for (int i = 0; i < N; ++i) { move_inside(i); if (i and press_button() == 2) move_outside(i); else roots.push_back(i), nbCC++; } vector<bool> isRoot(N); for (int r : roots) isRoot[r] = true; vector<int> toProcess; for (int i = 0; i < N; ++i) if (!isRoot[i]) toProcess.push_back(i); if (nbCC == 1) return N; for (int r : roots) { move_outside(r); toProcess.push_back(r); } set<int> inside; 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)popped.size() > N - mid * nbCC) { notProcessed.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) { if ((int)inside.size() == nbCC * mid) return mid; 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; } if (up * nbCC == (int)inside.size()) lo = up; } return lo; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...