Submission #836159

# Submission time Handle Problem Language Result Execution time Memory
836159 2023-08-24T08:07:55 Z Josia Toy Train (IOI17_train) C++17
0 / 100
2000 ms 1780 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 Incorrect 721 ms 1576 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 4th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2078 ms 1780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2083 ms 1236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 1484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 721 ms 1576 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -