# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
64827 | 2018-08-05T18:09:08 Z | mohammad_kilani | Toy Train (IOI17_train) | C++17 | 1622 ms | 263168 KB |
#include "train.h" #include <bits/stdc++.h> using namespace std; const int N = 5010; vector< int > res , a , g[N] , r; int n , vis[N] , vi = 0 , last; bool DFS(int node){ vis[node] = vi; if(a[node] == 0 && r[node]) return false; if(node == last) return true; for(int i=0;i<g[node].size();i++){ if(vis[g[node][i]] != vi && a[g[node][i]] == a[last]){ if(DFS(g[node][i])) return true; } } return false; } bool DFS2(int node){ vis[node] = vi; if(res[node] == a[last]) return true; for(int i=0;i<g[node].size();i++){ if(vis[g[node][i]] != vi && a[g[node][i]] == a[last]){ if(DFS2(g[node][i])) return true; } } return false; } bool DFS3(int node){ vis[node] = vi; if(res[node] != -1) return false; if(a[node] != a[last]) return true; for(int i=0;i<g[node].size();i++){ if(vis[g[node][i]] != vi) if(DFS3(g[node][i])) return true; } return false; } bool DFS4(int node){ vis[node] = vi; if(a[node] != a[last]) return (res[node] != a[node]); for(int i=0;i<g[node].size();i++){ if(vis[g[node][i]] != true && DFS4(g[node][i])) return true; } return false; } std::vector<int> who_wins(std::vector<int> A, std::vector<int> R, std::vector<int> u, std::vector<int> v) { a = A; n = (int)a.size(); r = R; res.resize(n , -1); for(int i = 0;i<(int)u.size();i++){ g[u[i]].push_back(v[i]); } for(int i=0;i<n;i++){ last = i; vi++; if(a[i] == 0 || r[i]){ for(int j = 0;j<g[i].size();j++){ if(a[g[i][j]] == a[i] && vis[g[i][j]] != vi && DFS(g[i][j])){ res[i] = a[i]; break; } } } } for(int i=0;i<n;i++){ if(res[i] != -1) continue; last = i; vi++; if(DFS2(i)) res[i] = a[i]; } for(int i=0;i<n;i++){ if(res[i] == -1){ vi++; last = i; if(!DFS3(i)) res[i] = a[i] ^ 1; } } for(int i=0;i<n;i++){ if(res[i] == -1){ vi++; last = i; if(DFS4(i)) res[i] = a[i]; } } return res; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 775 ms | 263168 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 751 ms | 263168 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 265 ms | 263168 KB | Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1622 ms | 263168 KB | Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1191 ms | 263168 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 775 ms | 263168 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |