# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
767307 | 2023-06-26T15:23:58 Z | APROHACK | 장난감 기차 (IOI17_train) | C++14 | 2000 ms | 1876 KB |
#include "train.h" #include<bits/stdc++.h> #define pb push_back #define ll long long #define ff first #define ss second #define past 2 #define ancestor 1 #define unvisited 0 using namespace std; int n; vector<bool>owner, charging; vector<int>adj[5001]; vector<int>adjInverso[5001]; bool isCycle[5001][2] ; // 0 Negative 1 Positive short int vis[5001]; vector<int>nodos; void memss(){ for(int i = 0 ; i < n ; i ++)vis[i] = 0; } bool dfs(int node){ ////cout << "were " << node << endl; bool isA = owner[node]; bool isCharging = charging[node]; vis[node] = 1; nodos.pb(node); for(int i = 0 ; i < adj[node].size() ; i ++){ if(!vis[adj[node][i]]){ if(dfs(adj[node][i]) == isA){ nodos.pop_back(); vis[node] = 0; return isA; } }else{ bool hayC = false; for(int j = nodos.size()-1 ; j>= 0 ; j --){ if(charging[nodos[j]])hayC = true; if(nodos[j] == adj[node][i])break; } if((hayC && isA) or (!hayC && !isA)){ nodos.pop_back(); vis[node] = 0; } if(hayC && isA)return true; else if(!hayC && !isA)return false; } } nodos.pop_back(); vis[node] = 0; return !isA; } void recorrer(int node){ vis[node] = ancestor; nodos.pb(node); for(int i = 0 ; i < adj[node].size() ; i ++){ if(vis[adj[node][i]] == past)continue; if(vis[adj[node][i]] == ancestor){ bool positive = false; for(int j = nodos.size()-1 ; j >= 0 ; j --){ if(charging[nodos[j]]){ positive = true; break; } if(nodos[j] == adj[node][i])break; } for(int j = nodos.size() - 1 ; j >= 0 ; j --){ if(positive)isCycle[nodos[j]][1] = true; else isCycle[nodos[j]][0] = true; if(nodos[j] == adj[node][i])break; } }else{ recorrer(adj[node][i]); } } vis[node] = past; nodos.pop_back(); } int ansFor[5001]; void dfs2(int node, int isCyclePos){ isCycle[node][isCyclePos] = true; vis[node] = past; for(int i = 0 ; i < adjInverso[node].size() ; i ++){ if(vis[adjInverso[node][i] ] == past)continue; dfs2(adjInverso[node][i], isCyclePos); } } std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) { n = a.size(); vector<int> res; memss(); bool all1 = true, all0 = true; for(int i = 0 ; i < n ; i ++){ owner.pb(a[i]); res.pb(0); charging.pb(r[i]); if(a[i] == 0)all1 = false; else all0 = false; } for(int i = 0 ; i < u.size() ; i ++){ adj[u[i]].pb(v[i]); adjInverso[v[i]].pb(u[i]); } if(all0 or all1){ memset(ansFor, -1, sizeof ansFor); for(int i = 0 ; i < n ; i ++){ if(vis[i] == unvisited)recorrer(i); } memss(); for(int i = 0 ; i < n ; i++){ if(all1 and isCycle[i][1]){ dfs2(i, 1); }else if(all0 and isCycle[i][0]){ dfs2(i, 0); } } for(int i = 0 ; i < n ; i ++){ if(all1 and isCycle[i][1])res[i] = 1; else if (all1)res[i] = 0; else if(isCycle[i][0])res[i] = 0; else res[i] = 1; } }else{ for(int i = 0 ; i < n ; i ++){ if(dfs(i)){ res[i] = 1; }else res[i] = 0; ansFor[i] = res[i]; } } return res; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1108 KB | Output is correct |
2 | Correct | 4 ms | 1108 KB | Output is correct |
3 | Correct | 4 ms | 1096 KB | Output is correct |
4 | Correct | 4 ms | 980 KB | Output is correct |
5 | Correct | 4 ms | 980 KB | Output is correct |
6 | Correct | 4 ms | 980 KB | Output is correct |
7 | Correct | 3 ms | 1020 KB | Output is correct |
8 | Correct | 3 ms | 980 KB | Output is correct |
9 | Correct | 3 ms | 980 KB | Output is correct |
10 | Correct | 3 ms | 980 KB | Output is correct |
11 | Correct | 3 ms | 980 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 0 ms | 468 KB | Output is correct |
3 | Correct | 0 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 0 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 468 KB | Output is correct |
7 | Correct | 0 ms | 468 KB | Output is correct |
8 | Correct | 0 ms | 468 KB | Output is correct |
9 | Correct | 1 ms | 468 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 1 ms | 468 KB | Output is correct |
13 | Correct | 0 ms | 468 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
15 | Correct | 1 ms | 468 KB | Output is correct |
16 | Correct | 0 ms | 468 KB | Output is correct |
17 | Correct | 1 ms | 468 KB | Output is correct |
18 | Correct | 0 ms | 468 KB | Output is correct |
19 | Correct | 0 ms | 468 KB | Output is correct |
20 | Correct | 1 ms | 468 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 1620 KB | Output is correct |
2 | Correct | 5 ms | 1620 KB | Output is correct |
3 | Correct | 5 ms | 1608 KB | Output is correct |
4 | Correct | 14 ms | 1620 KB | Output is correct |
5 | Correct | 9 ms | 1576 KB | Output is correct |
6 | Correct | 7 ms | 1364 KB | Output is correct |
7 | Correct | 7 ms | 1364 KB | Output is correct |
8 | Correct | 6 ms | 1364 KB | Output is correct |
9 | Correct | 5 ms | 1364 KB | Output is correct |
10 | Correct | 6 ms | 1364 KB | Output is correct |
11 | Correct | 6 ms | 1452 KB | Output is correct |
12 | Correct | 6 ms | 1492 KB | Output is correct |
13 | Correct | 22 ms | 1848 KB | Output is correct |
14 | Incorrect | 31 ms | 1840 KB | 3rd lines differ - on the 1st token, expected: '1', found: '0' |
15 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 1344 KB | Output is correct |
2 | Correct | 6 ms | 1236 KB | Output is correct |
3 | Correct | 7 ms | 1364 KB | Output is correct |
4 | Correct | 8 ms | 1364 KB | Output is correct |
5 | Correct | 6 ms | 1576 KB | Output is correct |
6 | Correct | 6 ms | 1588 KB | Output is correct |
7 | Correct | 6 ms | 1488 KB | Output is correct |
8 | Correct | 6 ms | 1456 KB | Output is correct |
9 | Correct | 6 ms | 1492 KB | Output is correct |
10 | Correct | 12 ms | 1876 KB | Output is correct |
11 | Correct | 12 ms | 1876 KB | Output is correct |
12 | Correct | 12 ms | 1848 KB | Output is correct |
13 | Correct | 10 ms | 1732 KB | Output is correct |
14 | Correct | 7 ms | 1484 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2071 ms | 1444 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1108 KB | Output is correct |
2 | Correct | 4 ms | 1108 KB | Output is correct |
3 | Correct | 4 ms | 1096 KB | Output is correct |
4 | Correct | 4 ms | 980 KB | Output is correct |
5 | Correct | 4 ms | 980 KB | Output is correct |
6 | Correct | 4 ms | 980 KB | Output is correct |
7 | Correct | 3 ms | 1020 KB | Output is correct |
8 | Correct | 3 ms | 980 KB | Output is correct |
9 | Correct | 3 ms | 980 KB | Output is correct |
10 | Correct | 3 ms | 980 KB | Output is correct |
11 | Correct | 3 ms | 980 KB | Output is correct |
12 | Correct | 1 ms | 468 KB | Output is correct |
13 | Correct | 0 ms | 468 KB | Output is correct |
14 | Correct | 0 ms | 468 KB | Output is correct |
15 | Correct | 1 ms | 468 KB | Output is correct |
16 | Correct | 0 ms | 468 KB | Output is correct |
17 | Correct | 1 ms | 468 KB | Output is correct |
18 | Correct | 0 ms | 468 KB | Output is correct |
19 | Correct | 0 ms | 468 KB | Output is correct |
20 | Correct | 1 ms | 468 KB | Output is correct |
21 | Correct | 1 ms | 468 KB | Output is correct |
22 | Correct | 1 ms | 468 KB | Output is correct |
23 | Correct | 1 ms | 468 KB | Output is correct |
24 | Correct | 0 ms | 468 KB | Output is correct |
25 | Correct | 1 ms | 468 KB | Output is correct |
26 | Correct | 1 ms | 468 KB | Output is correct |
27 | Correct | 0 ms | 468 KB | Output is correct |
28 | Correct | 1 ms | 468 KB | Output is correct |
29 | Correct | 0 ms | 468 KB | Output is correct |
30 | Correct | 0 ms | 468 KB | Output is correct |
31 | Correct | 1 ms | 468 KB | Output is correct |
32 | Correct | 5 ms | 1620 KB | Output is correct |
33 | Correct | 5 ms | 1620 KB | Output is correct |
34 | Correct | 5 ms | 1608 KB | Output is correct |
35 | Correct | 14 ms | 1620 KB | Output is correct |
36 | Correct | 9 ms | 1576 KB | Output is correct |
37 | Correct | 7 ms | 1364 KB | Output is correct |
38 | Correct | 7 ms | 1364 KB | Output is correct |
39 | Correct | 6 ms | 1364 KB | Output is correct |
40 | Correct | 5 ms | 1364 KB | Output is correct |
41 | Correct | 6 ms | 1364 KB | Output is correct |
42 | Correct | 6 ms | 1452 KB | Output is correct |
43 | Correct | 6 ms | 1492 KB | Output is correct |
44 | Correct | 22 ms | 1848 KB | Output is correct |
45 | Incorrect | 31 ms | 1840 KB | 3rd lines differ - on the 1st token, expected: '1', found: '0' |
46 | Halted | 0 ms | 0 KB | - |