제출 #628498

#제출 시각아이디문제언어결과실행 시간메모리
628498c28dnv9q3드문 곤충 (IOI22_insects)C++17
10 / 100
3077 ms1144 KiB
#include "insects.h" #include <vector> #include <numeric> #include <map> #include <set> #include <random> #include <algorithm> 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; random_device dev; mt19937 rng(dev()); uniform_int_distribution dist(0,N-1); set<pair<int,int>> precheck; vector<int> lookup(N); iota(lookup.begin(), lookup.end(), 0); shuffle(lookup.begin(), lookup.end(), rng); /*while (N >= 10 && precheck.size() < min(10000, 2*N)) { int a = dist(rng); int b = dist(rng); if (a == b) continue; int x = min(a,b); int y = max(a,b); if (precheck.count({x,y}) || ufind(x) == ufind(y)) continue; move_inside(lookup[x]); move_inside(lookup[y]); if (press_button() == 2) { umerge(x,y); } move_outside(lookup[x]); move_outside(lookup[y]); precheck.insert({x,y}); }*/ vector<pair<int,int>> reject; for (int i = 0; i < N; i++) { if (usz(i) != 1) continue; move_inside(lookup[i]); for (int j = 0; j < N; j++) { if (ufind(i) == ufind(j)) continue; if (usz(i) >= minsz) continue; bool halt = false; for (auto x : reject) { if ( (ufind(i) == ufind(x.first) && ufind(j) == ufind(x.second)) || (ufind(j) == ufind(x.first) && ufind(i) == ufind(x.second)) ) { halt = true; break; } } if (halt) continue; /* for (auto x : precheck) { if ( (ufind(x.first) == ufind(i) && ufind(x.second) == ufind(j)) || (ufind(x.first) == ufind(j) && ufind(x.second) == ufind(i)) ) { // they must be different halt = true; break; } } if (halt) continue;*/ move_inside(lookup[j]); if (press_button() == 2) umerge(j, i); else reject.push_back({i, j}); move_outside(lookup[j]); //checked.push_back(j); } move_outside(lookup[i]); minsz = min(minsz, usz(i)); } return minsz; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...