Submission #45477

# Submission time Handle Problem Language Result Execution time Memory
45477 2018-04-14T11:17:15 Z alenam0161 Toy Train (IOI17_train) C++17
38 / 100
2000 ms 7424 KB
#include "train.h"
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;
const int N = 5e3 + 7;
int n, m;

unordered_set<int> R;
vector<int> g[N], g1[N];
vector<int> A;

unordered_set<int> rev(const unordered_set<int> &fi){
	auto cur = fi;
	cur.clear();
	for (int i = 0; i < n; ++i){
		if (fi.count(i) == 0)cur.insert(i);
	}
	return cur;
}

unordered_set<int> Fw(int w, const unordered_set<int> &fi){
	unordered_set<int> cur = fi;
	queue<int> q;
	
	for (int x : fi)
		q.push(x);

	while (!q.empty()){
		auto it = q.front(); q.pop();
		for (auto to : g1[it]){
			if (cur.count(to) == 1)
				continue;

			bool __b = all_of(g[to].begin(), g[to].end(), [&](int x){return cur.count(x) == 1; });
			if (A[to] == w || __b)
			{
				cur.insert(to);
				q.push(to);
			} 
		}
	}
	return cur;
}
unordered_set<int> merge(const unordered_set<int> &fi, const unordered_set<int> &se){
	unordered_set<int> All;
	for (auto it : fi)
		if (se.count(it) == 1) All.insert(it);
	return All;
}
void pr(const unordered_set<int> &st){
	for (const auto &it : st){
		cout << it << " ";
	}
	cout << endl;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	::n = a.size();
	::A = a;
	::m = u.size();
	vector<int> res;
	for (int i = 0; i < n; ++i)
		if (r[i] == 1) R.insert(i);
	for (int i = 0; i < m; ++i){
		g[u[i]].push_back(v[i]);
		g1[v[i]].push_back(u[i]);
	}
	while (true){
		auto R_ex = Fw(1, R);
		auto X = rev(R_ex);
		auto X_ex = Fw(0, X);
		unordered_set<int> M = merge(R, X_ex);
		for (auto it : M)
			R.erase(it);
		if (M.size() == 0){
			auto ans = vector<int>(n, 1);
			for (const auto &it : X_ex)
				ans[it] = 0;
			return ans;
		}

	}
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1656 KB Output is correct
2 Correct 22 ms 1864 KB Output is correct
3 Correct 18 ms 1916 KB Output is correct
4 Correct 28 ms 2064 KB Output is correct
5 Correct 14 ms 2208 KB Output is correct
6 Correct 16 ms 2420 KB Output is correct
7 Correct 18 ms 2628 KB Output is correct
8 Correct 15 ms 2628 KB Output is correct
9 Correct 12 ms 2772 KB Output is correct
10 Correct 11 ms 2852 KB Output is correct
11 Correct 7 ms 2852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2852 KB Output is correct
2 Correct 2 ms 2852 KB Output is correct
3 Correct 2 ms 2852 KB Output is correct
4 Correct 2 ms 2852 KB Output is correct
5 Correct 3 ms 2852 KB Output is correct
6 Correct 3 ms 2852 KB Output is correct
7 Correct 2 ms 2852 KB Output is correct
8 Correct 2 ms 2852 KB Output is correct
9 Correct 2 ms 2852 KB Output is correct
10 Correct 2 ms 2852 KB Output is correct
11 Correct 2 ms 2852 KB Output is correct
12 Correct 2 ms 2852 KB Output is correct
13 Correct 2 ms 2852 KB Output is correct
14 Correct 2 ms 2852 KB Output is correct
15 Correct 2 ms 2852 KB Output is correct
16 Correct 3 ms 2852 KB Output is correct
17 Correct 3 ms 2852 KB Output is correct
18 Correct 2 ms 2852 KB Output is correct
19 Correct 2 ms 2852 KB Output is correct
20 Correct 2 ms 2852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1059 ms 3592 KB Output is correct
2 Correct 1952 ms 3976 KB Output is correct
3 Execution timed out 2068 ms 4164 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4164 KB Output is correct
2 Correct 27 ms 4164 KB Output is correct
3 Correct 17 ms 4284 KB Output is correct
4 Correct 19 ms 4744 KB Output is correct
5 Correct 23 ms 4824 KB Output is correct
6 Correct 22 ms 4868 KB Output is correct
7 Correct 32 ms 5104 KB Output is correct
8 Correct 16 ms 5428 KB Output is correct
9 Correct 18 ms 5624 KB Output is correct
10 Correct 15 ms 5940 KB Output is correct
11 Correct 14 ms 6148 KB Output is correct
12 Correct 26 ms 6352 KB Output is correct
13 Correct 16 ms 6352 KB Output is correct
14 Correct 16 ms 6384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 6704 KB Output is correct
2 Correct 23 ms 6980 KB Output is correct
3 Correct 16 ms 7116 KB Output is correct
4 Correct 16 ms 7324 KB Output is correct
5 Correct 3 ms 7324 KB Output is correct
6 Correct 13 ms 7324 KB Output is correct
7 Correct 15 ms 7324 KB Output is correct
8 Correct 10 ms 7324 KB Output is correct
9 Correct 10 ms 7324 KB Output is correct
10 Correct 4 ms 7324 KB Output is correct
11 Correct 8 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1656 KB Output is correct
2 Correct 22 ms 1864 KB Output is correct
3 Correct 18 ms 1916 KB Output is correct
4 Correct 28 ms 2064 KB Output is correct
5 Correct 14 ms 2208 KB Output is correct
6 Correct 16 ms 2420 KB Output is correct
7 Correct 18 ms 2628 KB Output is correct
8 Correct 15 ms 2628 KB Output is correct
9 Correct 12 ms 2772 KB Output is correct
10 Correct 11 ms 2852 KB Output is correct
11 Correct 7 ms 2852 KB Output is correct
12 Correct 2 ms 2852 KB Output is correct
13 Correct 2 ms 2852 KB Output is correct
14 Correct 2 ms 2852 KB Output is correct
15 Correct 2 ms 2852 KB Output is correct
16 Correct 3 ms 2852 KB Output is correct
17 Correct 3 ms 2852 KB Output is correct
18 Correct 2 ms 2852 KB Output is correct
19 Correct 2 ms 2852 KB Output is correct
20 Correct 2 ms 2852 KB Output is correct
21 Correct 2 ms 2852 KB Output is correct
22 Correct 2 ms 2852 KB Output is correct
23 Correct 2 ms 2852 KB Output is correct
24 Correct 2 ms 2852 KB Output is correct
25 Correct 2 ms 2852 KB Output is correct
26 Correct 2 ms 2852 KB Output is correct
27 Correct 3 ms 2852 KB Output is correct
28 Correct 3 ms 2852 KB Output is correct
29 Correct 2 ms 2852 KB Output is correct
30 Correct 2 ms 2852 KB Output is correct
31 Correct 2 ms 2852 KB Output is correct
32 Correct 1059 ms 3592 KB Output is correct
33 Correct 1952 ms 3976 KB Output is correct
34 Execution timed out 2068 ms 4164 KB Time limit exceeded
35 Halted 0 ms 0 KB -