Submission #836149

# Submission time Handle Problem Language Result Execution time Memory
836149 2023-08-24T08:00:12 Z Josia Toy Train (IOI17_train) C++17
5 / 100
2000 ms 1888 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;
int dfs(int v) {
	if (vis[v]) {
		if (dp[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;

	path.push_back(v);

	set<int> poss;
	for (int i: graph[v]) {
		poss.insert(dfs(i));
	}

	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);
		path.clear();
		res[i] = dfs(i);
	}

	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 791 ms 1640 KB Output is correct
2 Correct 290 ms 1264 KB Output is correct
3 Correct 137 ms 1064 KB Output is correct
4 Correct 52 ms 956 KB Output is correct
5 Correct 25 ms 912 KB Output is correct
6 Correct 15 ms 888 KB Output is correct
7 Correct 15 ms 852 KB Output is correct
8 Correct 14 ms 892 KB Output is correct
9 Correct 13 ms 848 KB Output is correct
10 Correct 11 ms 844 KB Output is correct
11 Correct 10 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 280 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 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 620 ms 1888 KB Output is correct
2 Correct 632 ms 1864 KB Output is correct
3 Correct 662 ms 1792 KB Output is correct
4 Execution timed out 2061 ms 1764 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2063 ms 1444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2061 ms 1588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 791 ms 1640 KB Output is correct
2 Correct 290 ms 1264 KB Output is correct
3 Correct 137 ms 1064 KB Output is correct
4 Correct 52 ms 956 KB Output is correct
5 Correct 25 ms 912 KB Output is correct
6 Correct 15 ms 888 KB Output is correct
7 Correct 15 ms 852 KB Output is correct
8 Correct 14 ms 892 KB Output is correct
9 Correct 13 ms 848 KB Output is correct
10 Correct 11 ms 844 KB Output is correct
11 Correct 10 ms 724 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 280 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Incorrect 1 ms 212 KB 3rd lines differ - on the 4th token, expected: '0', found: '1'
16 Halted 0 ms 0 KB -