제출 #628445

#제출 시각아이디문제언어결과실행 시간메모리
628445c28dnv9q3드문 곤충 (IOI22_insects)C++17
0 / 100
304 ms256 KiB
#include "insects.h" #include <vector> #include <numeric> #include <map> using namespace std; vector<int> p; vector<int> sz; int ufind(int i) { if (p[i] == i) return i; return p[i] = ufind(p[i]); } int usz(int i) { return sz[ufind(i)]; } void umerge(int a, int b) { if (ufind(a) == ufind(b)) return; p[a] = b; sz[b] += sz[a]; } int min_cardinality(int N) { p.resize(N); sz.resize(N); iota(p.begin(), p.end(), 0); fill(sz.begin(), sz.end(), 1); int minsz = N; for (int i = 0; i < N-1; i++) { if (usz(i) >= minsz) continue; move_inside(i); for (int j = 0; j < N; j++) { if (usz(i) >= minsz) continue; if (ufind(i) == ufind(j)) continue; move_inside(j); if (press_button() == 2) umerge(j, i); move_outside(j); } move_outside(i); minsz = min(minsz, usz(i)); } minsz = min(minsz, usz(N-1)); return minsz; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...