Submission #45490

# Submission time Handle Problem Language Result Execution time Memory
45490 2018-04-14T11:54:39 Z alenam0161 Toy Train (IOI17_train) C++17
38 / 100
2000 ms 2620 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> cur;
unordered_set<int> rev(const unordered_set<int> &fi){
	cur.clear();
	for (int i = 0; i < n; ++i){
		if (fi.count(i) == 0)cur.insert(i);
	}
	return cur;
}
queue<int> q;
unordered_set<int> Fw(int w, const unordered_set<int> &fi){
	cur = fi;
	while (!q.empty())q.pop();
	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;
 
			if (A[to] == w || all_of(g[to].begin(), g[to].end(), [&](const int &x){return cur.count(x) == 1; }))
			{
				cur.insert(to);
				q.push(to);
			} 
		}
	}
	return cur;
}
unordered_set<int> All;
unordered_set<int> merge(const unordered_set<int> &fi, const unordered_set<int> &se){
	All.clear();
	for (auto it : fi)
		if (se.count(it) == 1) All.insert(it);
	return All;
}
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]);
	}
	unordered_set<int> M;
	while (true){
		auto R_ex = Fw(1, R);
		auto X = rev(R_ex);
		auto X_ex = Fw(0, X);
		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 1784 KB Output is correct
2 Correct 34 ms 1784 KB Output is correct
3 Correct 19 ms 1964 KB Output is correct
4 Correct 20 ms 1964 KB Output is correct
5 Correct 15 ms 1964 KB Output is correct
6 Correct 15 ms 1964 KB Output is correct
7 Correct 12 ms 2096 KB Output is correct
8 Correct 15 ms 2096 KB Output is correct
9 Correct 12 ms 2096 KB Output is correct
10 Correct 12 ms 2096 KB Output is correct
11 Correct 8 ms 2096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2096 KB Output is correct
2 Correct 2 ms 2096 KB Output is correct
3 Correct 2 ms 2096 KB Output is correct
4 Correct 2 ms 2096 KB Output is correct
5 Correct 2 ms 2096 KB Output is correct
6 Correct 2 ms 2096 KB Output is correct
7 Correct 2 ms 2096 KB Output is correct
8 Correct 2 ms 2096 KB Output is correct
9 Correct 2 ms 2096 KB Output is correct
10 Correct 2 ms 2096 KB Output is correct
11 Correct 2 ms 2096 KB Output is correct
12 Correct 2 ms 2096 KB Output is correct
13 Correct 2 ms 2096 KB Output is correct
14 Correct 2 ms 2096 KB Output is correct
15 Correct 2 ms 2096 KB Output is correct
16 Correct 2 ms 2096 KB Output is correct
17 Correct 2 ms 2096 KB Output is correct
18 Correct 2 ms 2096 KB Output is correct
19 Correct 2 ms 2096 KB Output is correct
20 Correct 2 ms 2096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 946 ms 2500 KB Output is correct
2 Execution timed out 2058 ms 2500 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2500 KB Output is correct
2 Correct 18 ms 2500 KB Output is correct
3 Correct 19 ms 2500 KB Output is correct
4 Correct 19 ms 2620 KB Output is correct
5 Correct 20 ms 2620 KB Output is correct
6 Correct 21 ms 2620 KB Output is correct
7 Correct 19 ms 2620 KB Output is correct
8 Correct 17 ms 2620 KB Output is correct
9 Correct 15 ms 2620 KB Output is correct
10 Correct 15 ms 2620 KB Output is correct
11 Correct 14 ms 2620 KB Output is correct
12 Correct 15 ms 2620 KB Output is correct
13 Correct 16 ms 2620 KB Output is correct
14 Correct 14 ms 2620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2620 KB Output is correct
2 Correct 15 ms 2620 KB Output is correct
3 Correct 16 ms 2620 KB Output is correct
4 Correct 15 ms 2620 KB Output is correct
5 Correct 3 ms 2620 KB Output is correct
6 Correct 10 ms 2620 KB Output is correct
7 Correct 9 ms 2620 KB Output is correct
8 Correct 10 ms 2620 KB Output is correct
9 Correct 9 ms 2620 KB Output is correct
10 Correct 4 ms 2620 KB Output is correct
11 Correct 9 ms 2620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1784 KB Output is correct
2 Correct 34 ms 1784 KB Output is correct
3 Correct 19 ms 1964 KB Output is correct
4 Correct 20 ms 1964 KB Output is correct
5 Correct 15 ms 1964 KB Output is correct
6 Correct 15 ms 1964 KB Output is correct
7 Correct 12 ms 2096 KB Output is correct
8 Correct 15 ms 2096 KB Output is correct
9 Correct 12 ms 2096 KB Output is correct
10 Correct 12 ms 2096 KB Output is correct
11 Correct 8 ms 2096 KB Output is correct
12 Correct 2 ms 2096 KB Output is correct
13 Correct 2 ms 2096 KB Output is correct
14 Correct 2 ms 2096 KB Output is correct
15 Correct 2 ms 2096 KB Output is correct
16 Correct 2 ms 2096 KB Output is correct
17 Correct 2 ms 2096 KB Output is correct
18 Correct 2 ms 2096 KB Output is correct
19 Correct 2 ms 2096 KB Output is correct
20 Correct 2 ms 2096 KB Output is correct
21 Correct 2 ms 2096 KB Output is correct
22 Correct 2 ms 2096 KB Output is correct
23 Correct 2 ms 2096 KB Output is correct
24 Correct 2 ms 2096 KB Output is correct
25 Correct 2 ms 2096 KB Output is correct
26 Correct 2 ms 2096 KB Output is correct
27 Correct 2 ms 2096 KB Output is correct
28 Correct 2 ms 2096 KB Output is correct
29 Correct 2 ms 2096 KB Output is correct
30 Correct 2 ms 2096 KB Output is correct
31 Correct 2 ms 2096 KB Output is correct
32 Correct 946 ms 2500 KB Output is correct
33 Execution timed out 2058 ms 2500 KB Time limit exceeded
34 Halted 0 ms 0 KB -