제출 #659903

#제출 시각아이디문제언어결과실행 시간메모리
659903peijar드문 곤충 (IOI22_insects)C++17
99.78 / 100
73 ms428 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; set<int> calcInter(set<int> &a, set<int> &b) { set<int> ret; for (int x : a) if (b.count(x)) ret.insert(x); return ret; } 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); } int lo = 1, up = N / nbCC; // invariant : everything outside of toProcess has majority element <= lo // We never need to reconsider insects !! int toAdd = 0; while (lo < up) { int mid = (lo + up + 1) / 2; vector<int> popped; vector<int> insideMachine; for (int u : toProcess) { move_inside(u); if (press_button() > mid) popped.push_back(u), move_outside(u); else insideMachine.push_back(u); } if ((int)popped.size() == N - mid * nbCC) { for (int u : insideMachine) move_outside(u); toProcess = popped; N = popped.size(); toAdd += mid; lo = 0, up = min(N / nbCC, up - mid); } else { for (int u : insideMachine) move_outside(u); toProcess = insideMachine; N = toProcess.size(); up = mid - 1; } } return lo + toAdd; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...