제출 #672050

#제출 시각아이디문제언어결과실행 시간메모리
672050tbzard드문 곤충 (IOI22_insects)C++17
0 / 100
1 ms208 KiB
#include <bits/stdc++.h> #include "insects.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> pipii; typedef pair<pii, int> piipi; typedef pair<pii, pii> piipii; #define mp make_pair #define fi first #define se second #define all(a) (a).begin(), (a).end() #define sz(a) (int)(a).size() #define eb emplace_back // void move_inside(int i); // void move_outside(int i); // int press_button(); int p[2222], sz[2222]; bool asked[2222][2222]; int root(int a){ return p[a] == a?a:(p[a]=root(p[a])); } void merge(int a, int b, int n){ a = root(a), b = root(b); if(a != b){ p[a] = b; sz[b] += sz[a]; for(int i=1;i<=n;i++){ asked[b][i] |= asked[a][i]; asked[i][b] |= asked[i][a]; } } } int min_cardinality(int n){ for(int i=1;i<=n;i++) p[i] = i, sz[i] = 1; for(int i=1;i<=n;i++) asked[i][i] = 1; set<int> cur; for(int i=1;i<=n;i++) cur.insert(i); while(!cur.empty()){ int u = *cur.begin(); move_inside(u-1); int cnt = 1; for(int i=1;i<=n;i++){ if(asked[u][i]) continue; move_inside(i-1); int r = press_button(); if(r == 2){ asked[u][i] = 1; asked[i][u] = 1; merge(u, i, n); cnt++; cur.erase(cur.find(i)); } else{ asked[u][i] = 1; asked[i][u] = 1; } move_outside(i-1); } if(cnt == 1) return cnt; move_outside(u-1); } int ans = 1e9; for(int i=1;i<=n;i++){ int r = root(i); ans = min(ans, sz[r]); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...