Submission #1040434

#TimeUsernameProblemLanguageResultExecution timeMemory
1040434vjudge1Toy Train (IOI17_train)C++17
100 / 100
1082 ms4188 KiB
#include "train.h" #include<bits/stdc++.h> using namespace std; set<int>radj[5010],adj[5010]; set<int>inv(vector<int>v,set<int>st){ for(auto i:v) st.erase(i); return st; } vector<int>aset(set<int>v,vector<int>own){ vector<int>cnt(5000),don(5000); queue<int>q; vector<int>ans; for(auto i:v) q.push(i),don[i]=1; while(q.size()){ int x=q.front(); q.pop(); ans.push_back(x); for(auto i:radj[x]) { if(don[i])continue; if(own[i]) q.push(i),don[i]=1; else if(++cnt[i]==adj[i].size()) q.push(i),don[i]=1; } } return ans; } std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) { int N=a.size(),M=u.size(); std::vector<int> res(a.size()),bozo=a; for(auto&i:bozo)i=!i; for(int i=0;i<M;i++) adj[u[i]].insert(v[i]), radj[v[i]].insert(u[i]); set<int>charg,hav; for(int i=0;i<N;hav.insert(i++)) if(r[i])charg.insert(i); int CC=N; while(CC) { vector<int>v=aset(charg,a); if(v.size()==CC){ for(auto i:v) res[i]=1; break; } v=aset(inv(v,hav),bozo); for(auto i:v){ CC--; charg.erase(i); hav.erase(i); for(auto j:adj[i]) radj[j].erase(i); for(auto j:radj[i]) adj[j].erase(i); adj[i].clear(); radj[i].clear(); } } return res; }

Compilation message (stderr)

train.cpp: In function 'std::vector<int> aset(std::set<int>, std::vector<int>)':
train.cpp:22:29: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |             else if(++cnt[i]==adj[i].size())
      |                     ~~~~~~~~^~~~~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:41:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |         if(v.size()==CC){
      |            ~~~~~~~~^~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...