Submission #659890

#TimeUsernameProblemLanguageResultExecution timeMemory
659890peijarRarest Insects (IOI22_insects)C++17
53.16 / 100
239 ms424 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); int lo = 1, up = N / nbCC; // invariant : everything outside of toProcess has majority element >= lo while (lo < up) { int mid = (lo + up + 1) / 2; vector<int> kept; vector<int> popped; for (int i : toProcess) { move_inside(i); if (press_button() > mid) popped.push_back(i), move_outside(i); else kept.push_back(i); } int cntPopped = popped.size(); if (cntPopped == N - nbCC * mid) { lo = mid; toProcess = move(popped); } else { up = mid - 1; for (int i : kept) move_outside(i); } } return lo; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...