Submission #45486

# Submission time Handle Problem Language Result Execution time Memory
45486 2018-04-14T11:49:10 Z Abelyan Toy Train (IOI17_train) C++17
38 / 100
2000 ms 2424 KB
#include "train.h"
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <queue>
#pragma GCC optimize("unroll-loops")
using namespace std;

const int N = 5006;
int n, m;
vector<int> g[N],ing[N];
bool col[N],chrg[N];
unordered_set <int> R;

unordered_set<int> rev(unordered_set<int> &s){
	unordered_set<int> ans;
	for (int i = 0; i < n; i++){
		if (s.count(i) == 0) ans.insert(i);
	}
	return ans;
}
unordered_set<int> fa(unordered_set<int> &s){
	unordered_set<int> ans;
	queue<int> q;
	for (auto k : s){
		q.push(k);
		ans.insert(k);
	}
	while (!q.empty()){
		int v = q.front();
		q.pop();
		for (auto to : ing[v]){
			if (ans.count(to)) continue;
			bool mb = true;
			for (auto k : g[to]){
				mb &= ans.count(k) == 1;
			}
			if (col[to] || mb){
				ans.insert(to);
				q.push(to);
			}
		}
	}
	return ans;
}

unordered_set<int> fb(unordered_set<int> &s){
	unordered_set<int> ans;
	queue<int> q;
	for (auto k : s){
		q.push(k);
		ans.insert(k);
	}
	while (!q.empty()){
		int v = q.front();
		q.pop();
		for (auto to : ing[v]){
			if (ans.count(to)==1) continue;
			bool mb = true;
			for (auto k : g[to]){
				mb &= ans.count(k) == 1;
			}
			if (!col[to] || mb){
				ans.insert(to);
				q.push(to);
			}
		}
	}
	return ans;
}

unordered_set<int> intersect(unordered_set<int> &a, unordered_set<int> &b){
	unordered_set<int> ans;
	for (auto i : a){
		if (b.count(i)) ans.insert(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]].push_back(v[i]);
		ing[v[i]].push_back(u[i]);
	}
	for (int i = 0; i < n; i++){
		if (a[i]){
			col[i] = true;
		}
	}
	for (int i = 0; i < n; i++){
		if (r[i]) chrg[i] = true;
	}
	while (1){
		R.clear();
		for (int i = 0; i < n; i++){
			if (chrg[i]) R.insert(i);
		}
		unordered_set <int>  far = fa(R),gg=rev(far),x = fb(gg), ht = intersect(far, x);
		bool mb = false;
		for (auto k : ht){
			if (chrg[k]) mb = true, chrg[k] = false;
		}
		if (!mb){
			vector<int> ans(n,1);
			for (auto k : x){
				ans[k] = 0;
			}
			return ans;
		}
	}
}
/*
2 4 
0 1 
1 0 
0 0 
0 1 
1 0 
1 1 

*/
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1528 KB Output is correct
2 Correct 25 ms 1684 KB Output is correct
3 Correct 22 ms 1684 KB Output is correct
4 Correct 20 ms 1684 KB Output is correct
5 Correct 15 ms 1776 KB Output is correct
6 Correct 17 ms 1776 KB Output is correct
7 Correct 11 ms 1780 KB Output is correct
8 Correct 16 ms 1780 KB Output is correct
9 Correct 14 ms 1780 KB Output is correct
10 Correct 12 ms 1780 KB Output is correct
11 Correct 12 ms 1780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1780 KB Output is correct
2 Correct 2 ms 1780 KB Output is correct
3 Correct 2 ms 1780 KB Output is correct
4 Correct 3 ms 1780 KB Output is correct
5 Correct 2 ms 1780 KB Output is correct
6 Correct 2 ms 1780 KB Output is correct
7 Correct 2 ms 1780 KB Output is correct
8 Correct 2 ms 1780 KB Output is correct
9 Correct 2 ms 1780 KB Output is correct
10 Correct 2 ms 1780 KB Output is correct
11 Correct 2 ms 1780 KB Output is correct
12 Correct 2 ms 1780 KB Output is correct
13 Correct 2 ms 1780 KB Output is correct
14 Correct 2 ms 1780 KB Output is correct
15 Correct 2 ms 1780 KB Output is correct
16 Correct 2 ms 1780 KB Output is correct
17 Correct 2 ms 1780 KB Output is correct
18 Correct 3 ms 1780 KB Output is correct
19 Correct 2 ms 1780 KB Output is correct
20 Correct 2 ms 1780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1103 ms 2424 KB Output is correct
2 Execution timed out 2068 ms 2424 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2424 KB Output is correct
2 Correct 20 ms 2424 KB Output is correct
3 Correct 20 ms 2424 KB Output is correct
4 Correct 21 ms 2424 KB Output is correct
5 Correct 54 ms 2424 KB Output is correct
6 Correct 34 ms 2424 KB Output is correct
7 Correct 28 ms 2424 KB Output is correct
8 Correct 19 ms 2424 KB Output is correct
9 Correct 17 ms 2424 KB Output is correct
10 Correct 15 ms 2424 KB Output is correct
11 Correct 14 ms 2424 KB Output is correct
12 Correct 15 ms 2424 KB Output is correct
13 Correct 16 ms 2424 KB Output is correct
14 Correct 19 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2424 KB Output is correct
2 Correct 15 ms 2424 KB Output is correct
3 Correct 16 ms 2424 KB Output is correct
4 Correct 14 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 9 ms 2424 KB Output is correct
7 Correct 20 ms 2424 KB Output is correct
8 Correct 24 ms 2424 KB Output is correct
9 Correct 23 ms 2424 KB Output is correct
10 Correct 9 ms 2424 KB Output is correct
11 Correct 14 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1528 KB Output is correct
2 Correct 25 ms 1684 KB Output is correct
3 Correct 22 ms 1684 KB Output is correct
4 Correct 20 ms 1684 KB Output is correct
5 Correct 15 ms 1776 KB Output is correct
6 Correct 17 ms 1776 KB Output is correct
7 Correct 11 ms 1780 KB Output is correct
8 Correct 16 ms 1780 KB Output is correct
9 Correct 14 ms 1780 KB Output is correct
10 Correct 12 ms 1780 KB Output is correct
11 Correct 12 ms 1780 KB Output is correct
12 Correct 2 ms 1780 KB Output is correct
13 Correct 2 ms 1780 KB Output is correct
14 Correct 2 ms 1780 KB Output is correct
15 Correct 3 ms 1780 KB Output is correct
16 Correct 2 ms 1780 KB Output is correct
17 Correct 2 ms 1780 KB Output is correct
18 Correct 2 ms 1780 KB Output is correct
19 Correct 2 ms 1780 KB Output is correct
20 Correct 2 ms 1780 KB Output is correct
21 Correct 2 ms 1780 KB Output is correct
22 Correct 2 ms 1780 KB Output is correct
23 Correct 2 ms 1780 KB Output is correct
24 Correct 2 ms 1780 KB Output is correct
25 Correct 2 ms 1780 KB Output is correct
26 Correct 2 ms 1780 KB Output is correct
27 Correct 2 ms 1780 KB Output is correct
28 Correct 2 ms 1780 KB Output is correct
29 Correct 3 ms 1780 KB Output is correct
30 Correct 2 ms 1780 KB Output is correct
31 Correct 2 ms 1780 KB Output is correct
32 Correct 1103 ms 2424 KB Output is correct
33 Execution timed out 2068 ms 2424 KB Time limit exceeded
34 Halted 0 ms 0 KB -