# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
112295 | 2019-05-18T13:37:42 Z | gs14004 | Toy Train (IOI17_train) | C++17 | 268 ms | 1536 KB |
#include "train.h" #include <bits/stdc++.h> using namespace std; vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v){ vector<int> gph[5005]; int n = a.size(); int m = u.size(); vector<int> ret(n); vector<int> proc(n); for(int i=0; i<m; i++){ gph[v[i]].push_back(u[i]); } while(true){ int unproc = count(proc.begin(), proc.end(), 0); if(unproc == 0) break; vector<int> deg(n); queue<int> que; for(int i=0; i<m; i++){ if(!proc[u[i]] && !proc[v[i]]){ deg[u[i]]++; } } for(int i=0; i<n; i++){ if(!proc[i] && r[i]){ deg[i] = 0; que.push(i); } } vector<int> aReach; while(!que.empty()){ int x = que.front(); que.pop(); aReach.push_back(x); for(auto &j : gph[x]){ if(proc[j]) continue; if(a[j] == 1 && deg[j] > 0){ deg[j] = 0; que.push(j); } if(a[j] == 0){ deg[j]--; if(deg[j] == 0) que.push(j); } } } if(aReach.size() == unproc){ for(auto &i : aReach) proc[i] = 1, ret[i] = 1; } else{ fill(deg.begin(), deg.end(), 0); for(int i=0; i<m; i++){ if(!proc[u[i]] && !proc[v[i]]){ deg[u[i]]++; } } vector<int> rem(n); for(auto &i : aReach) rem[i] = 1; for(int i=0; i<n; i++){ if(!proc[i] && !rem[i]){ que.push(i); } } while(!que.empty()){ int x = que.front(); que.pop(); proc[x] = 1; ret[x] = 0; for(auto &j : gph[x]){ if(proc[j]) continue; if(a[j] == 0 && deg[j] > 0){ deg[j] = 0; que.push(j); } if(a[j] == 1){ deg[j]--; if(deg[j] == 0) que.push(j); } } } } } return ret; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 896 KB | Output is correct |
2 | Correct | 7 ms | 1024 KB | Output is correct |
3 | Correct | 7 ms | 1024 KB | Output is correct |
4 | Correct | 7 ms | 1024 KB | Output is correct |
5 | Correct | 6 ms | 896 KB | Output is correct |
6 | Correct | 6 ms | 900 KB | Output is correct |
7 | Correct | 6 ms | 1024 KB | Output is correct |
8 | Correct | 7 ms | 896 KB | Output is correct |
9 | Correct | 6 ms | 896 KB | Output is correct |
10 | Correct | 7 ms | 896 KB | Output is correct |
11 | Correct | 6 ms | 900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 512 KB | Output is correct |
4 | Correct | 2 ms | 512 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 512 KB | Output is correct |
7 | Correct | 2 ms | 512 KB | Output is correct |
8 | Correct | 2 ms | 512 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 512 KB | Output is correct |
16 | Correct | 3 ms | 512 KB | Output is correct |
17 | Correct | 2 ms | 512 KB | Output is correct |
18 | Correct | 3 ms | 512 KB | Output is correct |
19 | Correct | 3 ms | 512 KB | Output is correct |
20 | Correct | 3 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 112 ms | 1220 KB | Output is correct |
2 | Correct | 222 ms | 1420 KB | Output is correct |
3 | Correct | 268 ms | 1536 KB | Output is correct |
4 | Correct | 9 ms | 1408 KB | Output is correct |
5 | Incorrect | 11 ms | 1408 KB | 3rd lines differ - on the 854th token, expected: '1', found: '0' |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1024 KB | Output is correct |
2 | Correct | 9 ms | 1280 KB | Output is correct |
3 | Correct | 9 ms | 1280 KB | Output is correct |
4 | Correct | 10 ms | 1280 KB | Output is correct |
5 | Correct | 9 ms | 1280 KB | Output is correct |
6 | Correct | 9 ms | 1408 KB | Output is correct |
7 | Correct | 9 ms | 1280 KB | Output is correct |
8 | Correct | 8 ms | 1280 KB | Output is correct |
9 | Correct | 8 ms | 1280 KB | Output is correct |
10 | Correct | 9 ms | 1408 KB | Output is correct |
11 | Correct | 8 ms | 1408 KB | Output is correct |
12 | Correct | 9 ms | 1408 KB | Output is correct |
13 | Correct | 9 ms | 1280 KB | Output is correct |
14 | Correct | 9 ms | 1280 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 1152 KB | 3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 896 KB | Output is correct |
2 | Correct | 7 ms | 1024 KB | Output is correct |
3 | Correct | 7 ms | 1024 KB | Output is correct |
4 | Correct | 7 ms | 1024 KB | Output is correct |
5 | Correct | 6 ms | 896 KB | Output is correct |
6 | Correct | 6 ms | 900 KB | Output is correct |
7 | Correct | 6 ms | 1024 KB | Output is correct |
8 | Correct | 7 ms | 896 KB | Output is correct |
9 | Correct | 6 ms | 896 KB | Output is correct |
10 | Correct | 7 ms | 896 KB | Output is correct |
11 | Correct | 6 ms | 900 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 512 KB | Output is correct |
15 | Correct | 2 ms | 512 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 3 ms | 512 KB | Output is correct |
18 | Correct | 2 ms | 512 KB | Output is correct |
19 | Correct | 2 ms | 512 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 384 KB | Output is correct |
22 | Correct | 3 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 2 ms | 512 KB | Output is correct |
27 | Correct | 3 ms | 512 KB | Output is correct |
28 | Correct | 2 ms | 512 KB | Output is correct |
29 | Correct | 3 ms | 512 KB | Output is correct |
30 | Correct | 3 ms | 512 KB | Output is correct |
31 | Correct | 3 ms | 512 KB | Output is correct |
32 | Correct | 112 ms | 1220 KB | Output is correct |
33 | Correct | 222 ms | 1420 KB | Output is correct |
34 | Correct | 268 ms | 1536 KB | Output is correct |
35 | Correct | 9 ms | 1408 KB | Output is correct |
36 | Incorrect | 11 ms | 1408 KB | 3rd lines differ - on the 854th token, expected: '1', found: '0' |
37 | Halted | 0 ms | 0 KB | - |