# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
836160 |
2023-08-24T08:08:52 Z |
Josia |
Toy Train (IOI17_train) |
C++17 |
|
2000 ms |
1772 KB |
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> graph;
vector<bool> own;
vector<bool> station;
vector<int> dp;
vector<bool> vis;
vector<int> path;
vector<int> pathExpl;
int dfs(int v) {
if (vis[v]) {
if (pathExpl[v] == -1) return dp[v];
vector<int> cycle;
bool contains = 0;
for (int i = path.size()-1; i>=0; i--) {
cycle.push_back(path[i]);
if (station[path[i]]) contains=1;
if (path[i] == v) break;
}
return contains;
}
vis[v] = 1;
pathExpl[v] = path.size();
path.push_back(v);
set<int> poss;
for (int i: graph[v]) {
poss.insert(dfs(i));
}
pathExpl[v] = -1;
path.pop_back();
if (own[v]) {
if (poss.count(1)) return dp[v]=1;
return dp[v]=0;
}
else {
if (poss.count(0)) return dp[v]=0;
return dp[v]=1;
}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n = a.size();
graph.assign(n, vector<int>());
for (int i = 0; i<(int)u.size(); i++) {
graph[u[i]].push_back(v[i]);
}
own.resize(n);
station.resize(n);
for (int i = 0; i<n; i++) {
own[i] = a[i];
station[i] = r[i];
}
vector<int> res(n);
for (int i = 0; i<n; i++) {
vis.assign(n, 0);
dp.assign(n, -1);
pathExpl.assign(n, -1);
path.clear();
res[i] = dfs(i);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
809 ms |
1576 KB |
Output is correct |
2 |
Correct |
328 ms |
1108 KB |
Output is correct |
3 |
Correct |
146 ms |
972 KB |
Output is correct |
4 |
Correct |
57 ms |
852 KB |
Output is correct |
5 |
Correct |
33 ms |
968 KB |
Output is correct |
6 |
Correct |
23 ms |
724 KB |
Output is correct |
7 |
Correct |
22 ms |
724 KB |
Output is correct |
8 |
Correct |
22 ms |
724 KB |
Output is correct |
9 |
Correct |
20 ms |
724 KB |
Output is correct |
10 |
Correct |
19 ms |
724 KB |
Output is correct |
11 |
Correct |
18 ms |
784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 4th token, expected: '0', found: '1' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
582 ms |
1772 KB |
Output is correct |
2 |
Correct |
648 ms |
1748 KB |
Output is correct |
3 |
Correct |
677 ms |
1620 KB |
Output is correct |
4 |
Execution timed out |
2035 ms |
1576 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2070 ms |
1320 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2041 ms |
1472 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
809 ms |
1576 KB |
Output is correct |
2 |
Correct |
328 ms |
1108 KB |
Output is correct |
3 |
Correct |
146 ms |
972 KB |
Output is correct |
4 |
Correct |
57 ms |
852 KB |
Output is correct |
5 |
Correct |
33 ms |
968 KB |
Output is correct |
6 |
Correct |
23 ms |
724 KB |
Output is correct |
7 |
Correct |
22 ms |
724 KB |
Output is correct |
8 |
Correct |
22 ms |
724 KB |
Output is correct |
9 |
Correct |
20 ms |
724 KB |
Output is correct |
10 |
Correct |
19 ms |
724 KB |
Output is correct |
11 |
Correct |
18 ms |
784 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 4th token, expected: '0', found: '1' |
16 |
Halted |
0 ms |
0 KB |
- |