Submission #1143435

#TimeUsernameProblemLanguageResultExecution timeMemory
1143435steveonalexKeys (IOI21_keys)C++20
37 / 100
3099 ms105344 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(a, b);} ll lcm(ll a, ll b){return a / gcd(a, b) * 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()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} double rngesus_d(double l, double r){ double cur = rngesus(0, MASK(60) - 1); cur /= MASK(60) - 1; return l + cur * (r - l); } 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 = 3e5 + 69, INF = 1e9 + 69; int n, m; vector<pair<int, int>> graph[N]; bool add_set(vector<int> &S, vector<bool> &mark, int c){ if (mark[c] == false){ mark[c] = true; S.push_back(c); return true; } return false; } void clear_set(vector<int> &S, vector<bool> &mark){ for(int i: S) mark[i] = false; S.clear(); } vector<int> find_reachable(vector<int> r, vector<int> U, vector<int> V, vector<int> C) { n = r.size(), m = U.size(); int mi = INF; vector<int> optimal_vertice_set; for(int i = 0; i < m; ++i){ int u= U[i], v = V[i], c = C[i]; graph[u].push_back({v, c}); graph[v].push_back({u, c}); } for(int i = 0; i < n; ++i) shuffle(ALL(graph[i]), rng); vector<int> perm(n); for(int i = 0; i < n; ++i) perm[i] = i; shuffle(ALL(perm), rng); vector<int> p(n, 1); vector<vector<int>> reached(n); vector<bool> color_mark(n), vertice_mark(n); vector<int> reached_color, reached_vertices; vector<vector<int>> waiting_edge(n); for(int i: perm){ add_set(reached_vertices, vertice_mark, i); vector<int> st; st.push_back(i); vector<int> color_used; while(st.size()){ int u = st.back(); st.pop_back(); add_set(reached_color, color_mark, r[u]); bool stop_signal = false; for(int v: waiting_edge[r[u]]){ if (add_set(reached_vertices, vertice_mark, v)) { if (p[v] > mi) { p[i] = p[v]; stop_signal = true; break; } else if (binary_search(ALL(reached[v]), i)){ p[i] = p[v]; stop_signal = true; break; } st.push_back(v); } } if (stop_signal || p[i] > mi) break; waiting_edge[r[u]].clear(); for(pair<int, int> v: graph[u]) { if (color_mark[v.second]) { if (add_set(reached_vertices, vertice_mark, v.first)){ if (p[v.first] > mi) { p[i] = p[v.first]; stop_signal = true; break; } else if (binary_search(ALL(reached[v.first]), i)){ p[i] = p[v.first]; stop_signal = true; break; } st.push_back(v.first); } } else{ if (vertice_mark[v.first] == false){ color_used.push_back(v.second); waiting_edge[v.second].push_back(v.first); } } } maximize(p[i], reached_vertices.size()); if (stop_signal || p[i] > mi) break; } reached[i] = reached_vertices; sort(ALL(reached[i])); minimize(mi, p[i]); for(int i: color_used) waiting_edge[i].clear(); clear_set(reached_color, color_mark); clear_set(reached_vertices, vertice_mark); } vector<int> ans(n); for(int i = 0; i < n; ++i) { if (mi == p[i]){ ans[i] = true; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...