Submission #721133

#TimeUsernameProblemLanguageResultExecution timeMemory
721133Jarif_RahmanKeys (IOI21_keys)C++17
37 / 100
3060 ms43104 KiB
#include "keys.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int n, m; vector<int> r; vector<vector<pair<int, int>>> graph; vector<bool> candidate; vector<vector<int>> waiting_list; vector<bool> has_key; vector<bool> bl; void reduce_candidates(int s){ vector<int> has_key_v, waiting_list_v, reachable; has_key[r[s]] = 1; has_key_v.pb(r[s]); queue<int> Q; Q.push(s); while(!Q.empty()){ int nd = Q.front(); Q.pop(); if(bl[nd]) continue; bl[nd] = 1; reachable.pb(nd); if(candidate[nd] && nd != s){ candidate[s] = 0; break; } if(!has_key[r[nd]]){ for(int x: waiting_list[r[nd]]) if(!bl[x]) Q.push(x); waiting_list[r[nd]].clear(); has_key[r[nd]] = 1; has_key_v.pb(r[nd]); } for(auto [x, c]: graph[nd]) if(!bl[x]){ if(has_key[c]) Q.push(x); else{ waiting_list[c].pb(x); waiting_list_v.pb(c); } } } for(int x: has_key_v) has_key[x] = 0; for(int x: waiting_list_v) waiting_list[x].clear(); for(int x: reachable) bl[x] = 0; } int P; vector<int> ans, p; void bfs(int s){ vector<int> has_key_v, waiting_list_v, reachable; has_key[r[s]] = 1; has_key_v.pb(r[s]); queue<int> Q; Q.push(s); while(!Q.empty()){ int nd = Q.front(); Q.pop(); if(bl[nd]) continue; bl[nd] = 1; reachable.pb(nd); if(!has_key[r[nd]]){ for(int x: waiting_list[r[nd]]) if(!bl[x]) Q.push(x); waiting_list[r[nd]].clear(); has_key[r[nd]] = 1; has_key_v.pb(r[nd]); } for(auto [x, c]: graph[nd]) if(!bl[x]){ if(has_key[c]) Q.push(x); else{ waiting_list[c].pb(x); waiting_list_v.pb(c); } } } for(int x: has_key_v) has_key[x] = 0; for(int x: waiting_list_v) waiting_list[x].clear(); for(int x: reachable) bl[x] = 0; if(reachable.size() < P){ P = reachable.size(); for(int x: p) ans[x] = 0; p = reachable; for(int x: reachable) ans[x] = 1; } else if(reachable.size() == P){ p.insert(p.begin(), reachable.begin(), reachable.end()); for(int x: reachable) ans[x] = 1; } } vector<int> find_reachable(vector<int> _r, vector<int> U, vector<int> V, vector<int> C){ swap(r, _r); n = r.size(), m = U.size(); graph.resize(n); candidate.assign(n, 1); has_key.assign(n, 0); bl.assign(n, 0); waiting_list.resize(n); ans.resize(n); P = n; for(int i = 0; i < m; i++){ graph[U[i]].pb({V[i], C[i]}); graph[V[i]].pb({U[i], C[i]}); } vector<int> o(n); for(int i = 0; i < n; i++) o[i] = i; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); shuffle(o.begin(), o.end(), rng); for(int i = 0; i < n; i++) reduce_candidates(o[i]); for(int s = 0; s < n; s++) if(candidate[s]) bfs(s); return ans; }

Compilation message (stderr)

keys.cpp: In function 'void bfs(int)':
keys.cpp:91:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   91 |     if(reachable.size() < P){
      |        ~~~~~~~~~~~~~~~~~^~~
keys.cpp:97:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   97 |     else if(reachable.size() == P){
      |             ~~~~~~~~~~~~~~~~~^~~~
#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...