Submission #790307

#TimeUsernameProblemLanguageResultExecution timeMemory
790307Valaki2Toy Train (IOI17_train)C++14
12 / 100
334 ms1592 KiB
#include "train.h" #include <bits/stdc++.h> using namespace std; #define pb push_back const int maxn = 5000; int n, m; vector<int> g[1 + maxn], rg[1 + maxn]; int own[1 + maxn], charge[1 + maxn]; bool has_self[1 + maxn]; int charged; bool good[1 + maxn]; bool good_cycle; void decide() { for(int i = 1; i <= n; i++) { if(charge[i]) { charged = i; } } good[charged] = true; for(int iter = 1; iter <= n; iter++) { for(int cur = 1; cur <= n; cur++) { bool this_good; if(own[cur] == 1) { this_good = false; for(int nei : g[cur]) { if(good[nei]) { this_good = true; } } } else { this_good = true; for(int nei : g[cur]) { if(!good[nei]) { this_good = false; } } } if(this_good) { good[cur] = true; if(cur == charged) { good_cycle = true; } } } } } vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { n = a.size(); m = u.size(); for(int i = 0; i < m; i++) { g[u[i] + 1].pb(v[i] + 1); rg[v[i] + 1].pb(u[i] + 1); if(u[i] == v[i]) { has_self[u[i] + 1] = true; } } for(int i = 1; i <= n; i++) { own[i] = a[i - 1]; charge[i] = r[i - 1]; } decide(); vector<int> res(n, 0); if(good_cycle) { for(int i = 0; i < n; i++) { res[i] = good[i + 1]; } } 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...