제출 #1187320

#제출 시각아이디문제언어결과실행 시간메모리
1187320steveonalexFriends (BOI17_friends)C++20
100 / 100
172 ms6916 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1ULL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(abs(a), abs(b));} ll lcm(ll a, ll b){return abs(a) / gcd(a, b) * abs(b);} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ull mask){return __builtin_popcountll(mask);} int ctz(ull mask){return __builtin_ctzll(mask);} int logOf(ull mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); // mt19937_64 rng(1); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const int N = 2525; int n, p, q; vector<int> graph[N]; vector<vector<int>> ans; vector<int> gen_adj(vector<int> v){ remove_dup(v); vector<int> ans; for(int i: v) for(int j: graph[i]) if (!binary_search(ALL(v), j)) ans.push_back(j); remove_dup(ans); return ans; } vector<int> subtract_set(vector<int> A, vector<int> B){ int j = 0; vector<int> ans; for(int i: A){ while(j < (int) B.size() && B[j] < i) j++; if (j == (int) B.size() || i != B[j]) ans.push_back(i); } return ans; } int count_adj(vector<int> v){ remove_dup(v); int ans = 0; for(int i: v) { ans += subtract_set(graph[i], v).size(); } return ans; } void dfs(vector<int> v, set<vector<int>> &S, vector<int> &found_ans){ if (found_ans.size()) return; if (S.insert(v).second == false) return; vector<int> adj = gen_adj(v); if ((int) v.size() + (int) adj.size() > p + q) return; if (count_adj(v) <= q){ found_ans = v; return; } if ((int)v.size() >= p) return; for(int i: adj){ vector<int> _v = v; _v.push_back(i); for(int j = _v.size() - 1; j >= 1; --j) if (_v[j-1] > _v[j]){ swap(_v[j-1], _v[j]); } dfs(_v, S, found_ans); if (found_ans.size()) return; } } void solve(){ cin >> n >> p >> q; for(int i = 0; i < n; ++i){ int m; cin >> m; graph[i].resize(m); for(int &j: graph[i]) cin >> j; sort(ALL(graph[i])); } #define get_detention(){cout << "detention\n"; return;} for(int i = 0; i < n; ++i) if ((int)graph[i].size() >= p + q) get_detention(); for(int i = 0; i < n; ++i) { for(int j: graph[i]){ if (!binary_search(ALL(graph[j]), i)){ get_detention(); } } } set<vector<int>> S; vector<int> marked(n); for(int i = 0; i < n; ++i) if (!marked[i]){ vector<int> v = {i}; vector<int> found_ans; dfs(v, S, found_ans); if (found_ans.empty()){ get_detention(); } ans.push_back(found_ans); for(int j: found_ans) marked[j] = 1; } for(int i = 0; i < (int) ans.size(); ++i) for(int j = i+1; j < (int) ans.size(); ++j){ vector<int> sigma1 = subtract_set(ans[i], ans[j]), sigma2 = subtract_set(ans[j], ans[i]); if (count_adj(sigma1) <= q){ ans[i] = sigma1; } else if (count_adj(sigma2) <= q){ ans[j] = sigma2; } else{ assert(false); } } cout << "home\n"; int cnt = 0; for(auto i: ans) cnt += (i.size() > 0); cout << cnt << "\n"; for(auto i: ans){ if (i.size()){ cout << i.size() << " "; printArr(i); } } } int main(void){ ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); clock_t start = clock(); solve(); cerr << "Time elapsed: " << clock() - start << "ms!\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...