# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
420797 | 2021-06-08T13:58:39 Z | AugustinasJucas | Toy Train (IOI17_train) | C++14 | 1061 ms | 1116 KB |
//#include "train.h" #include <bits/stdc++.h> using namespace std; vector<int> charg; vector<int> priklauso; int n; const int dydis = 5e3 + 10; bool vis[dydis] = {}; bool can[dydis] = {}; int onS[dydis] = {}; bool can1[dydis] = {}; vector<int> gr[dydis]; bool dfs(int v){ if(onS[v]) return 0; if(vis[v]) return can[v]; vis[v] = 1; if(charg[v]) { can[v] = 1; return 1; } //cout << "dfs, v = " << v << endl; bool ret = 0; for(auto x : gr[v]){ onS[v]++; ret = ret | dfs(x); onS[v]--; } can[v] = ret; return ret; } bool dfs1(int v){ if(onS[v]) return 0; if(vis[v]) return can1[v]; vis[v] = 1; if(can[v]) { can1[v] = 1; return 1; } bool ret = 0; for(auto x : gr[v]){ onS[x]++; ret = ret | dfs1(x); onS[x]--; } can1[v] = ret; return ret; } vector<int> viskasPirmo(){ vector<int> ret(n, 0); for(int i = 0; i < n; i++){ // pradedu i for(int j = 0; j < n; j++) vis[j] = onS[j] = can[j] = can1[j] = 0; // cout << "i = " << i << endl; dfs(i); // cout << "gaunam, kad pasiekti ch gales: "; for(int j = 0; j < n; j++) if(can[j]) cout << j << ", "; cout << endl; for(int j = 0; j < n; j++) vis[j] = onS[j] = 0; for(int j = 0; j < n; j++) if(charg[j]) can[j] = 0; for(int j = 0; j < n; j++) if(charg[j]) ret[i] = ret[i] || dfs1(j); } return ret; } vector<int> viskasAntro(){ vector<int> ret(n); return ret; } vector<int> vienCharg(){ vector<int> ret(n); return ret; } vector<bool> isEnd(5001, 0); vector<int> prm(){ vector<int> ret(n, 0); for(int i = 0; i < n; i++){ int v = i; // cout << "i = " << i << endl; while(true){ // cout << "v = " << v << ", end = " << isEnd[v] << endl; if(isEnd[v] && priklauso[v] == charg[v]){ ret[i] = priklauso[v]; break; }else{ if(gr[v].size() == 1 && gr[v][0] == v){ ret[i] = charg[v]; break; }else{ v++; } } } } return ret; } vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { vector<int> res(a.size()); priklauso = a; charg = r; n = a.size(); for(int i = 0; i < (int)u.size(); i++){ gr[u[i]].push_back(v[i]); // gr[v[i]].push_back(u[i]); } int cnt[2] = {0}; for(auto x : a) cnt[x]++; int rc = 0; for(auto x : r) rc += x; bool pirmasSub = 1; for(int i = 0 ; i < u.size(); i++) { if(v[i] == u[i]) isEnd[v[i]] = 1; if(v[i] - u[i] == 0 || v[i]-u[i] == 1) continue; pirmasSub = 0; } if(pirmasSub){ return prm(); } if(cnt[1] == 0){ return viskasPirmo(); }else if(cnt[0] == 0){ return viskasAntro(); }else if(rc == 0){ return vienCharg(); } //for(int i = 0; i < n; i++) return res; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 716 KB | Output is correct |
2 | Correct | 4 ms | 716 KB | Output is correct |
3 | Correct | 4 ms | 716 KB | Output is correct |
4 | Correct | 7 ms | 840 KB | Output is correct |
5 | Correct | 4 ms | 840 KB | Output is correct |
6 | Correct | 4 ms | 844 KB | Output is correct |
7 | Correct | 4 ms | 844 KB | Output is correct |
8 | Correct | 6 ms | 844 KB | Output is correct |
9 | Correct | 9 ms | 808 KB | Output is correct |
10 | Correct | 5 ms | 844 KB | Output is correct |
11 | Correct | 4 ms | 844 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 332 KB | 3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 1100 KB | Output is correct |
2 | Correct | 7 ms | 1116 KB | Output is correct |
3 | Correct | 7 ms | 1100 KB | Output is correct |
4 | Incorrect | 7 ms | 1100 KB | 3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1061 ms | 984 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 | Incorrect | 8 ms | 972 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 | 4 ms | 716 KB | Output is correct |
2 | Correct | 4 ms | 716 KB | Output is correct |
3 | Correct | 4 ms | 716 KB | Output is correct |
4 | Correct | 7 ms | 840 KB | Output is correct |
5 | Correct | 4 ms | 840 KB | Output is correct |
6 | Correct | 4 ms | 844 KB | Output is correct |
7 | Correct | 4 ms | 844 KB | Output is correct |
8 | Correct | 6 ms | 844 KB | Output is correct |
9 | Correct | 9 ms | 808 KB | Output is correct |
10 | Correct | 5 ms | 844 KB | Output is correct |
11 | Correct | 4 ms | 844 KB | Output is correct |
12 | Incorrect | 1 ms | 332 KB | 3rd lines differ - on the 2nd token, expected: '1', found: '0' |
13 | Halted | 0 ms | 0 KB | - |