Submission #45489

# Submission time Handle Problem Language Result Execution time Memory
45489 2018-04-14T11:52:36 Z alenam0161 Toy Train (IOI17_train) C++17
100 / 100
995 ms 10096 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;

void rev(vector<bool> &fi){
	for (int i = 0; i < fi.size(); i++)
		fi[i] = !fi[i];
}

void Fw(int w, vector<bool> &fi){
	static queue<int> q;
	for (int i = 0; i < fi.size(); i++)
		if (fi[i])
			q.push(i);

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

			if (A[to] == w || all_of(g[to].begin(), g[to].end(), [&](int x){return fi[x] == 1; }))
			{
				fi[to] = true;
				q.push(to);
			}
		}
	}
}

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;
	
	vector<bool> R;
	for (auto it : r)
		R.push_back(it);

	for (int i = 0; i < m; ++i){
		g[u[i]].push_back(v[i]);
		g1[v[i]].push_back(u[i]);
	}
	while (true){
		static vector<bool> X;
		X = R;
		Fw(1, X);
		rev(X);
		Fw(0, X);

		int cnt = 0;
		for (int i = 0; i < n; i++)
			if (R[i] && X[i])
			{
				cnt++;
				R[i] = false;
			}

		if (cnt == 0){
			auto ans = vector<int>(n, 1);
			for (int i = 0; i < n; i++)
				if (X[i])
					ans[i] = 0;
			return ans;
		}
	}
	return res;
}

Compilation message

train.cpp: In function 'void rev(std::vector<bool>&)':
train.cpp:18:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < fi.size(); i++)
                  ~~^~~~~~~~~~~
train.cpp: In function 'void Fw(int, std::vector<bool>&)':
train.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < fi.size(); i++)
                  ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1144 KB Output is correct
2 Correct 9 ms 1144 KB Output is correct
3 Correct 9 ms 1324 KB Output is correct
4 Correct 9 ms 1400 KB Output is correct
5 Correct 7 ms 1432 KB Output is correct
6 Correct 12 ms 1448 KB Output is correct
7 Correct 10 ms 1448 KB Output is correct
8 Correct 8 ms 1448 KB Output is correct
9 Correct 7 ms 1540 KB Output is correct
10 Correct 7 ms 1540 KB Output is correct
11 Correct 6 ms 1540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1540 KB Output is correct
2 Correct 2 ms 1540 KB Output is correct
3 Correct 2 ms 1540 KB Output is correct
4 Correct 2 ms 1540 KB Output is correct
5 Correct 2 ms 1540 KB Output is correct
6 Correct 2 ms 1540 KB Output is correct
7 Correct 2 ms 1540 KB Output is correct
8 Correct 2 ms 1540 KB Output is correct
9 Correct 2 ms 1540 KB Output is correct
10 Correct 2 ms 1540 KB Output is correct
11 Correct 2 ms 1540 KB Output is correct
12 Correct 2 ms 1540 KB Output is correct
13 Correct 2 ms 1540 KB Output is correct
14 Correct 2 ms 1540 KB Output is correct
15 Correct 2 ms 1540 KB Output is correct
16 Correct 2 ms 1540 KB Output is correct
17 Correct 2 ms 1540 KB Output is correct
18 Correct 2 ms 1540 KB Output is correct
19 Correct 2 ms 1540 KB Output is correct
20 Correct 2 ms 1540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 1792 KB Output is correct
2 Correct 219 ms 1792 KB Output is correct
3 Correct 314 ms 1880 KB Output is correct
4 Correct 12 ms 2092 KB Output is correct
5 Correct 13 ms 2176 KB Output is correct
6 Correct 14 ms 2376 KB Output is correct
7 Correct 12 ms 2548 KB Output is correct
8 Correct 11 ms 2812 KB Output is correct
9 Correct 11 ms 2880 KB Output is correct
10 Correct 11 ms 3212 KB Output is correct
11 Correct 11 ms 3348 KB Output is correct
12 Correct 10 ms 3504 KB Output is correct
13 Correct 12 ms 3848 KB Output is correct
14 Correct 12 ms 4056 KB Output is correct
15 Correct 18 ms 4264 KB Output is correct
16 Correct 11 ms 4504 KB Output is correct
17 Correct 12 ms 4704 KB Output is correct
18 Correct 455 ms 4704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4704 KB Output is correct
2 Correct 11 ms 4704 KB Output is correct
3 Correct 12 ms 4780 KB Output is correct
4 Correct 21 ms 4780 KB Output is correct
5 Correct 21 ms 4780 KB Output is correct
6 Correct 13 ms 4780 KB Output is correct
7 Correct 13 ms 4780 KB Output is correct
8 Correct 11 ms 4780 KB Output is correct
9 Correct 11 ms 4780 KB Output is correct
10 Correct 11 ms 4780 KB Output is correct
11 Correct 11 ms 4832 KB Output is correct
12 Correct 13 ms 4832 KB Output is correct
13 Correct 12 ms 4832 KB Output is correct
14 Correct 15 ms 4832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4832 KB Output is correct
2 Correct 11 ms 4832 KB Output is correct
3 Correct 14 ms 4832 KB Output is correct
4 Correct 11 ms 4832 KB Output is correct
5 Correct 3 ms 4832 KB Output is correct
6 Correct 6 ms 4832 KB Output is correct
7 Correct 7 ms 4832 KB Output is correct
8 Correct 8 ms 4832 KB Output is correct
9 Correct 8 ms 4832 KB Output is correct
10 Correct 3 ms 4832 KB Output is correct
11 Correct 7 ms 4832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1144 KB Output is correct
2 Correct 9 ms 1144 KB Output is correct
3 Correct 9 ms 1324 KB Output is correct
4 Correct 9 ms 1400 KB Output is correct
5 Correct 7 ms 1432 KB Output is correct
6 Correct 12 ms 1448 KB Output is correct
7 Correct 10 ms 1448 KB Output is correct
8 Correct 8 ms 1448 KB Output is correct
9 Correct 7 ms 1540 KB Output is correct
10 Correct 7 ms 1540 KB Output is correct
11 Correct 6 ms 1540 KB Output is correct
12 Correct 2 ms 1540 KB Output is correct
13 Correct 2 ms 1540 KB Output is correct
14 Correct 2 ms 1540 KB Output is correct
15 Correct 2 ms 1540 KB Output is correct
16 Correct 2 ms 1540 KB Output is correct
17 Correct 2 ms 1540 KB Output is correct
18 Correct 2 ms 1540 KB Output is correct
19 Correct 2 ms 1540 KB Output is correct
20 Correct 2 ms 1540 KB Output is correct
21 Correct 2 ms 1540 KB Output is correct
22 Correct 2 ms 1540 KB Output is correct
23 Correct 2 ms 1540 KB Output is correct
24 Correct 2 ms 1540 KB Output is correct
25 Correct 2 ms 1540 KB Output is correct
26 Correct 2 ms 1540 KB Output is correct
27 Correct 2 ms 1540 KB Output is correct
28 Correct 2 ms 1540 KB Output is correct
29 Correct 2 ms 1540 KB Output is correct
30 Correct 2 ms 1540 KB Output is correct
31 Correct 2 ms 1540 KB Output is correct
32 Correct 126 ms 1792 KB Output is correct
33 Correct 219 ms 1792 KB Output is correct
34 Correct 314 ms 1880 KB Output is correct
35 Correct 12 ms 2092 KB Output is correct
36 Correct 13 ms 2176 KB Output is correct
37 Correct 14 ms 2376 KB Output is correct
38 Correct 12 ms 2548 KB Output is correct
39 Correct 11 ms 2812 KB Output is correct
40 Correct 11 ms 2880 KB Output is correct
41 Correct 11 ms 3212 KB Output is correct
42 Correct 11 ms 3348 KB Output is correct
43 Correct 10 ms 3504 KB Output is correct
44 Correct 12 ms 3848 KB Output is correct
45 Correct 12 ms 4056 KB Output is correct
46 Correct 18 ms 4264 KB Output is correct
47 Correct 11 ms 4504 KB Output is correct
48 Correct 12 ms 4704 KB Output is correct
49 Correct 455 ms 4704 KB Output is correct
50 Correct 13 ms 4704 KB Output is correct
51 Correct 11 ms 4704 KB Output is correct
52 Correct 12 ms 4780 KB Output is correct
53 Correct 21 ms 4780 KB Output is correct
54 Correct 21 ms 4780 KB Output is correct
55 Correct 13 ms 4780 KB Output is correct
56 Correct 13 ms 4780 KB Output is correct
57 Correct 11 ms 4780 KB Output is correct
58 Correct 11 ms 4780 KB Output is correct
59 Correct 11 ms 4780 KB Output is correct
60 Correct 11 ms 4832 KB Output is correct
61 Correct 13 ms 4832 KB Output is correct
62 Correct 12 ms 4832 KB Output is correct
63 Correct 15 ms 4832 KB Output is correct
64 Correct 12 ms 4832 KB Output is correct
65 Correct 11 ms 4832 KB Output is correct
66 Correct 14 ms 4832 KB Output is correct
67 Correct 11 ms 4832 KB Output is correct
68 Correct 3 ms 4832 KB Output is correct
69 Correct 6 ms 4832 KB Output is correct
70 Correct 7 ms 4832 KB Output is correct
71 Correct 8 ms 4832 KB Output is correct
72 Correct 8 ms 4832 KB Output is correct
73 Correct 3 ms 4832 KB Output is correct
74 Correct 7 ms 4832 KB Output is correct
75 Correct 200 ms 5036 KB Output is correct
76 Correct 285 ms 5208 KB Output is correct
77 Correct 429 ms 5668 KB Output is correct
78 Correct 412 ms 5748 KB Output is correct
79 Correct 381 ms 5832 KB Output is correct
80 Correct 13 ms 6040 KB Output is correct
81 Correct 13 ms 6376 KB Output is correct
82 Correct 14 ms 6436 KB Output is correct
83 Correct 13 ms 6628 KB Output is correct
84 Correct 13 ms 6876 KB Output is correct
85 Correct 13 ms 7084 KB Output is correct
86 Correct 14 ms 7292 KB Output is correct
87 Correct 13 ms 7500 KB Output is correct
88 Correct 21 ms 7700 KB Output is correct
89 Correct 14 ms 7916 KB Output is correct
90 Correct 24 ms 8096 KB Output is correct
91 Correct 21 ms 8332 KB Output is correct
92 Correct 37 ms 8644 KB Output is correct
93 Correct 47 ms 8744 KB Output is correct
94 Correct 41 ms 8956 KB Output is correct
95 Correct 44 ms 9164 KB Output is correct
96 Correct 168 ms 9272 KB Output is correct
97 Correct 599 ms 9560 KB Output is correct
98 Correct 914 ms 9768 KB Output is correct
99 Correct 995 ms 10096 KB Output is correct
100 Correct 470 ms 10096 KB Output is correct