# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
286596 | 2020-08-30T15:12:55 Z | stoyan_malinin | Toy Train (IOI17_train) | C++14 | 1239 ms | 26424 KB |
#include "train.h" //#include "grader.cpp" #include <vector> #include <assert.h> #include <iostream> #include <algorithm> #include <functional> using namespace std; const int MAXN = 5005; int n; vector <int> adj[MAXN]; int owner[MAXN], charging[MAXN]; int guessSubtask(vector <int> a, vector <int> r, vector <int> u, vector <int> v) { bool sub1 = true; for(int i = 0;i<u.size();i++) { if(u[i]!=v[i] && u[i]+1!=v[i]) { sub1 = false; break; } } if(sub1==true) return 1; bool sub3 = true; for(int i = 0;i<a.size();i++) { if(a[i]!=1) { sub3 = false; break; } } if(sub3==true) return 3; return -1; } vector <int> solve1() { vector <int> res(n, -1); for(int s = 0;s<n;s++) { int x = s; while(true) { int goal = -1; if(owner[x]==1) { if(charging[x]==1) goal = x; else goal = x + 1; bool found = false; for(int y: adj[x]) { if(y==goal) { found =true; break; } } if(found==true) { if(goal==x) { res[s] = true; break; } else { x = x + 1; } } else { if(goal==x) { x = x + 1; } else { res[s] = false; break; } } } else { if(charging[x]==1) goal = x + 1; else goal = x; bool found = false; for(int y: adj[x]) { if(y==goal) { found =true; break; } } if(found==true) { if(goal==x) { res[s] = false; break; } else { x = x + 1; } } else { if(goal==x) { x = x + 1; } else { res[s] = true; break; } } } } } return res; } bool reachable[MAXN][MAXN]; vector <int> solve3() { vector <int> res(n, -1); function <void(int, int, int)> dfsMark = [&](int x, int start, int depth) { if(depth!=0) reachable[start][x] = true; for(int y: adj[x]) { if(reachable[start][y]==false) dfsMark(y, start, depth+1); } }; for(int i = 0;i<n;i++) dfsMark(i, i, 0); vector <int> chargingStations; for(int i = 0;i<n;i++) { if(charging[i]==1) chargingStations.push_back(i); } vector <bool> goodCycle(n, false); for(int x = 0;x<n;x++) { bool ans = false; for(int station: chargingStations) { if(reachable[x][station]==true && reachable[station][x]==true) { ans = true; break; } } if(charging[x]==true) { for(int i = 0;i<n;i++) { if(i==x) continue; if(reachable[x][i]==true && reachable[i][x]==true) { ans = true; break; } } } goodCycle[x] = ans; //cout << "goodCycle[" << x << "] = " << ans << '\n'; } for(int s = 0;s<n;s++) { //cout << " ---- " << s << " --- " << '\n'; res[s] = goodCycle[s]; for(int x = 0;x<n;x++) { //cout << x << " -> " << reachable[s][x] << '\n'; if(reachable[s][x]==true && goodCycle[x]==true) { res[s] = true; break; } } } return res; } vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { n = a.size(); for(int i = 0;i<n;i++) { owner[i] = a[i]; charging[i] = r[i]; } for(int i = 0;i<u.size();i++) { adj[ u[i] ].push_back(v[i]); } for(int i = 0;i<n;i++) { sort(adj[i].begin(), adj[i].end()); auto it = unique(adj[i].begin(), adj[i].end()); adj[i].resize(it-adj[i].begin()); } int subtask = guessSubtask(a, r, u, v); return solve3(); return {}; } /* 3 3 1 1 1 1 0 0 0 0 1 0 2 1 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 413 ms | 25468 KB | 3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 512 KB | 3rd lines differ - on the 8th token, expected: '0', found: '1' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 370 ms | 26316 KB | Output is correct |
2 | Correct | 429 ms | 26412 KB | Output is correct |
3 | Correct | 474 ms | 26292 KB | Output is correct |
4 | Correct | 1214 ms | 26240 KB | Output is correct |
5 | Correct | 914 ms | 26296 KB | Output is correct |
6 | Correct | 748 ms | 26036 KB | Output is correct |
7 | Correct | 535 ms | 26040 KB | Output is correct |
8 | Correct | 385 ms | 25912 KB | Output is correct |
9 | Correct | 408 ms | 25924 KB | Output is correct |
10 | Correct | 422 ms | 26048 KB | Output is correct |
11 | Correct | 378 ms | 26048 KB | Output is correct |
12 | Correct | 84 ms | 25420 KB | Output is correct |
13 | Correct | 1224 ms | 26248 KB | Output is correct |
14 | Correct | 1239 ms | 26424 KB | Output is correct |
15 | Correct | 1225 ms | 26392 KB | Output is correct |
16 | Correct | 1206 ms | 26292 KB | Output is correct |
17 | Correct | 1200 ms | 26388 KB | Output is correct |
18 | Correct | 644 ms | 25976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1049 ms | 26076 KB | 3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1237 ms | 26308 KB | 3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 413 ms | 25468 KB | 3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 | Halted | 0 ms | 0 KB | - |