제출 #839324

#제출 시각아이디문제언어결과실행 시간메모리
839324andrei_boaca열쇠 (IOI21_keys)C++17
100 / 100
766 ms56684 KiB
#include <vector> #include <bits/stdc++.h> #include "keys.h" //#include "grader.cpp" using namespace std; mt19937_64 rng(chrono::steady_clock().now().time_since_epoch().count()); typedef pair<int,int> pii; int cnt[300005],use[300005],fin[300005],have[300005],my[300005]; set<int> setik; vector<pii> muchii[300005]; vector<int> block[300005]; vector<int> inblock; void plsclean() { for(int i:inblock) block[i].clear(); inblock.clear(); } int bfs(int x) { queue<int> coada; int rez=1; coada.push(x); use[x]=x+1; vector<int> viz; while(!coada.empty()) { int nod=coada.front(); coada.pop(); int c=my[nod]; if(have[c]!=x+1) { have[c]=x+1; for(int i:block[c]) if(use[i]!=x+1) { if(fin[i]) return 1e6; use[i]=x+1; rez++; viz.push_back(i); coada.push(i); } block[c].clear(); } for(pii i:muchii[nod]) { int a=i.first; int need=i.second; if(use[a]==x+1) continue; if(have[need]==x+1) { if(fin[a]) return 1e6; use[a]=x+1; rez++; viz.push_back(a); coada.push(a); } else { block[need].push_back(a); inblock.push_back(need); } } } for(int i:viz) cnt[i]=min(cnt[i],rez); return rez; } int n,minim=1e9; std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) { std::vector<int> ans(r.size(), 0); n=r.size(); vector<int> ord; for(int i=0;i<n;i++) { my[i]=r[i]; cnt[i]=1e6; ord.push_back(i); } vector<int> p; for(int i=0;i<u.size();i++) { int a=u[i]; int b=v[i]; int cheie=c[i]; p.push_back(a); p.push_back(b); muchii[a].push_back({b,cheie}); muchii[b].push_back({a,cheie}); } shuffle(p.begin(),p.end(),rng); for(int i:p) if(!fin[i]) { cnt[i]=min(cnt[i],bfs(i)); plsclean(); minim=min(minim,cnt[i]); fin[i]=1; } for(int i:ord) if(!fin[i]) { cnt[i]=min(cnt[i],bfs(i)); plsclean(); minim=min(minim,cnt[i]); fin[i]=1; } for(int i=0;i<n;i++) if(cnt[i]==minim) ans[i]=1; return ans; }

컴파일 시 표준 에러 (stderr) 메시지

keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:84:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for(int i=0;i<u.size();i++)
      |                 ~^~~~~~~~~
keys.cpp:111:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  111 |     for(int i=0;i<n;i++)
      |     ^~~
keys.cpp:114:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  114 |  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...