Submission #415656

# Submission time Handle Problem Language Result Execution time Memory
415656 2021-06-01T10:36:45 Z SeDunion Toy Train (IOI17_train) C++17
28 / 100
274 ms 1764 KB
#include "train.h"
#include<bits/stdc++.h>
using namespace std;

const int A = 1;
const int B = 0;

vector<int>g[5005], rg[5005];

int n, m;

int deg[5005];

queue<int>q;

vector<int>f(const int type, vector<int>&S, vector<int>&a) {
	for (int i = 0 ; i < n ; ++ i) {
		deg[i] = g[i].size();
	}
	for (int i : S) {
		deg[i] = -1;
		q.push(i);
	}
	while (q.size()) {
		int v = q.front(); q.pop();
		for (int from : rg[v]) if (deg[from] != -1) {
			if (a[from] == type) {
				deg[from] = -1;
				q.push(from);
			} else {
				if (--deg[from] == 0) {
					deg[from] = -1;
					q.push(from);
				}
			}
		}
	}
	vector<int>ans;
	for (int i = 0 ; i < n ; ++ i) {
		if (deg[i] == -1) {
			ans.emplace_back(i);
		}
	}
	return ans;
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	n = a.size();
	m = u.size();
	for (int i = 0 ; i < m ; ++ i) {
		g[u[i]].emplace_back(v[i]);
		rg[v[i]].emplace_back(u[i]);
	}
	vector<int>answer(n, -1);
	vector<int>R;
	vector<int>fa;
	vector<int>nfa;
	vector<int>infa;
	vector<int>fb;
	while (true) {
		R.clear();
		for (int i = 0 ; i < n ; ++ i) {
			if (r[i] && answer[i] == -1) {
				R.emplace_back(i);
			}
		}
		if (R.empty()) {
			for (int i = 0 ; i < n ; ++ i) {
				if (answer[i] == -1) {
					answer[i] = 0;
				}
			}
			break;
		}
		fa = f(A, R, a);
		infa.assign(n, 0);
		for (int i : fa) infa[i] = 1;
		nfa.clear();
		for (int i = 0 ; i < n ; ++ i) {
			if (answer[i] == -1 && infa[i] == 0) {
				nfa.emplace_back(i);
			}
		}
		fb = f(B, nfa, a);
		if (fb.empty()) {
			for (int i = 0 ; i < n ; ++ i) {
				if (answer[i] == -1) {
					answer[i] = 1;
				}
			}
			break;
		}
		for (int i : fb) answer[i] = 0;
	}
	return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1228 KB Output is correct
2 Correct 8 ms 1192 KB Output is correct
3 Correct 7 ms 1228 KB Output is correct
4 Correct 7 ms 1184 KB Output is correct
5 Correct 7 ms 1228 KB Output is correct
6 Correct 7 ms 1228 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 9 ms 1228 KB Output is correct
9 Correct 6 ms 1160 KB Output is correct
10 Correct 6 ms 1100 KB Output is correct
11 Correct 8 ms 1192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Incorrect 1 ms 460 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 107 ms 1740 KB Output is correct
2 Correct 198 ms 1764 KB Output is correct
3 Correct 274 ms 1756 KB Output is correct
4 Correct 10 ms 1612 KB Output is correct
5 Incorrect 14 ms 1612 KB 3rd lines differ - on the 11th token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1528 KB Output is correct
2 Correct 10 ms 1484 KB Output is correct
3 Correct 11 ms 1688 KB Output is correct
4 Correct 10 ms 1612 KB Output is correct
5 Correct 10 ms 1612 KB Output is correct
6 Correct 9 ms 1612 KB Output is correct
7 Correct 10 ms 1612 KB Output is correct
8 Correct 11 ms 1560 KB Output is correct
9 Correct 9 ms 1608 KB Output is correct
10 Correct 10 ms 1668 KB Output is correct
11 Correct 11 ms 1700 KB Output is correct
12 Correct 13 ms 1580 KB Output is correct
13 Correct 13 ms 1708 KB Output is correct
14 Correct 10 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1612 KB Output is correct
2 Correct 11 ms 1612 KB Output is correct
3 Correct 10 ms 1580 KB Output is correct
4 Correct 9 ms 1484 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 5 ms 1224 KB Output is correct
7 Correct 7 ms 1172 KB Output is correct
8 Correct 6 ms 1228 KB Output is correct
9 Correct 7 ms 1228 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 7 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1228 KB Output is correct
2 Correct 8 ms 1192 KB Output is correct
3 Correct 7 ms 1228 KB Output is correct
4 Correct 7 ms 1184 KB Output is correct
5 Correct 7 ms 1228 KB Output is correct
6 Correct 7 ms 1228 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 9 ms 1228 KB Output is correct
9 Correct 6 ms 1160 KB Output is correct
10 Correct 6 ms 1100 KB Output is correct
11 Correct 8 ms 1192 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Incorrect 1 ms 460 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
20 Halted 0 ms 0 KB -