# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132632 | 2019-07-19T09:05:00 Z | rondojim | Toy Train (IOI17_train) | C++17 | 361 ms | 3072 KB |
#include "train.h" #include<vector> #include<iostream> #include<queue> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) vector<int> nei[10000]; vector<int> inv[10000]; bool active[10000]; int owner[10000]; int charge[10000]; int n; bool S[10000]; int count[10000]; int reference; void extend(int node){ if(S[node])return; S[node]=true; //cout<<node<<endl; rep(i,0,inv[node].size()){ int v=inv[node][i]; if(active[v]){ count[v]++; if(!S[v]){ if(reference==owner[v]){ //cout<<v<<endl; extend(v); }else{ if(count[v]==nei[v].size()){ extend(v); } } } } } } void solve(){ //rep(i,0,n)cout<<active[i]<<" "; //cout<<endl; reference=1; rep(i,0,n)count[i]=0; rep(i,0,n){ S[i]=false; } rep(i,0,n){ if(charge[i] && active[i])extend(i); } int cont=0; rep(i,0,n){ if(!S[i] && active[i])S[i]=true; else S[i]=false; cont+=S[i]; //cout<<S[i]<<endl; //cout<<S[i]<<" "; }//cout<<endl; if(cont==0)return; reference=0; rep(i,0,n)count[i]=0; queue<int> q; rep(i,0,n){ if(S[i] && active[i]){ q.push(i); S[i]=false; } } while(!q.empty()){ extend(q.front()); q.pop(); } rep(i,0,n){ if(active[i] && S[i]){ active[i]=false; } } solve(); } std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) { n=a.size(); rep(i,0,n){ owner[i]=a[i]; charge[i]=r[i]; } rep(i,0,u.size()){ nei[u[i]].push_back(v[i]);inv[v[i]].push_back(u[i]); } rep(i,0,n)active[i]=true; solve(); vector<int> answer; rep(i,0,n){ answer.push_back(active[i]); } return answer; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1528 KB | Output is correct |
2 | Correct | 8 ms | 1532 KB | Output is correct |
3 | Correct | 8 ms | 1528 KB | Output is correct |
4 | Correct | 8 ms | 1528 KB | Output is correct |
5 | Correct | 8 ms | 1528 KB | Output is correct |
6 | Correct | 8 ms | 1532 KB | Output is correct |
7 | Correct | 7 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1528 KB | Output is correct |
9 | Correct | 7 ms | 1528 KB | Output is correct |
10 | Correct | 7 ms | 1400 KB | Output is correct |
11 | Correct | 7 ms | 1400 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 888 KB | Output is correct |
2 | Correct | 3 ms | 760 KB | Output is correct |
3 | Correct | 3 ms | 888 KB | Output is correct |
4 | Correct | 3 ms | 888 KB | Output is correct |
5 | Correct | 2 ms | 760 KB | Output is correct |
6 | Correct | 2 ms | 760 KB | Output is correct |
7 | Correct | 2 ms | 760 KB | Output is correct |
8 | Incorrect | 2 ms | 760 KB | 3rd lines differ - on the 2nd token, expected: '0', found: '1' |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 129 ms | 2452 KB | Output is correct |
2 | Correct | 250 ms | 2784 KB | Output is correct |
3 | Correct | 361 ms | 3072 KB | Output is correct |
4 | Correct | 13 ms | 2040 KB | Output is correct |
5 | Incorrect | 14 ms | 2040 KB | 3rd lines differ - on the 11th token, expected: '0', found: '1' |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 1788 KB | Output is correct |
2 | Correct | 13 ms | 1784 KB | Output is correct |
3 | Correct | 13 ms | 1912 KB | Output is correct |
4 | Correct | 12 ms | 1912 KB | Output is correct |
5 | Correct | 12 ms | 1912 KB | Output is correct |
6 | Correct | 12 ms | 1912 KB | Output is correct |
7 | Correct | 12 ms | 1912 KB | Output is correct |
8 | Correct | 12 ms | 1912 KB | Output is correct |
9 | Correct | 11 ms | 1784 KB | Output is correct |
10 | Correct | 13 ms | 1912 KB | Output is correct |
11 | Correct | 12 ms | 1912 KB | Output is correct |
12 | Correct | 12 ms | 1912 KB | Output is correct |
13 | Correct | 13 ms | 2040 KB | Output is correct |
14 | Correct | 12 ms | 1912 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 2040 KB | Output is correct |
2 | Correct | 12 ms | 2040 KB | Output is correct |
3 | Correct | 13 ms | 2040 KB | Output is correct |
4 | Correct | 11 ms | 1884 KB | Output is correct |
5 | Correct | 3 ms | 860 KB | Output is correct |
6 | Correct | 7 ms | 1528 KB | Output is correct |
7 | Correct | 8 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1528 KB | Output is correct |
9 | Correct | 8 ms | 1528 KB | Output is correct |
10 | Correct | 4 ms | 1016 KB | Output is correct |
11 | Correct | 8 ms | 1400 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1528 KB | Output is correct |
2 | Correct | 8 ms | 1532 KB | Output is correct |
3 | Correct | 8 ms | 1528 KB | Output is correct |
4 | Correct | 8 ms | 1528 KB | Output is correct |
5 | Correct | 8 ms | 1528 KB | Output is correct |
6 | Correct | 8 ms | 1532 KB | Output is correct |
7 | Correct | 7 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1528 KB | Output is correct |
9 | Correct | 7 ms | 1528 KB | Output is correct |
10 | Correct | 7 ms | 1400 KB | Output is correct |
11 | Correct | 7 ms | 1400 KB | Output is correct |
12 | Correct | 2 ms | 888 KB | Output is correct |
13 | Correct | 3 ms | 760 KB | Output is correct |
14 | Correct | 3 ms | 888 KB | Output is correct |
15 | Correct | 3 ms | 888 KB | Output is correct |
16 | Correct | 2 ms | 760 KB | Output is correct |
17 | Correct | 2 ms | 760 KB | Output is correct |
18 | Correct | 2 ms | 760 KB | Output is correct |
19 | Incorrect | 2 ms | 760 KB | 3rd lines differ - on the 2nd token, expected: '0', found: '1' |
20 | Halted | 0 ms | 0 KB | - |