Submission #95257

#TimeUsernameProblemLanguageResultExecution timeMemory
95257andy627Toy Train (IOI17_train)C++17
100 / 100
534 ms1892 KiB
#include "train.h" #include <bits/stdc++.h> #define N 5005 using namespace std; vector<int>g[N],rev[N]; bool f[N],iq[N],ans[N],ig[N];int goal[N],fc[N],a[N]; int n,m,k; void getfunx(int t) // calculate function : t=1 then A, t=0 then B result : bool array f { for(int i=0;i<n;i++) fc[i]=iq[i]=0; queue<int>que; for(int i=0;i<n;i++){ if(!ig[i]&&f[i]){ iq[i]=true; que.push(i); } } while(que.size()){ int i=que.front(); que.pop(); f[i]=true; for(auto &it : rev[i]){ if(ig[it]) continue; fc[it]++; if(iq[it]) continue; if(a[it]==t){ iq[it]=true; que.push(it); } else if(fc[it]==goal[it]){ iq[it]=true; que.push(it); } } } } vector<int> who_wins(vector<int> A,vector<int> r,vector<int> u,vector<int> v) { n=A.size(),m=u.size(),k=r.size(); for(int i=0;i<n;i++) a[i]=A[i]; vector<int> res(n); for(int i=0;i<m;i++){ g[u[i]].push_back(v[i]); goal[u[i]]++; rev[v[i]].push_back(u[i]); } while(1){ for(int i=0;i<n;i++) if(!ig[i]) f[i]=r[i]; getfunx(1); bool isans=true; for(int i=0;i<n;i++){ if(ig[i]) continue; if(!f[i]) isans=false; f[i]=!f[i]; } if(isans){ for(int i=0;i<n;i++) if(!ig[i]) ans[i]=true; break; } getfunx(0); for(int i=0;i<n;i++){ if(!ig[i]&&f[i]){ ig[i]=true; for(auto &it : rev[i]) goal[it]--; } } } for(int i=0;i<n;i++) res[i]=ans[i]; return res; }

Compilation message (stderr)

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:43:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(int i=0;i<n;i++)
     ^~~
train.cpp:45:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  vector<int> res(n);
  ^~~~~~
train.cpp:79:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(int i=0;i<n;i++)
     ^~~
train.cpp:81:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  return res;
  ^~~~~~
#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...