Submission #408463

# Submission time Handle Problem Language Result Execution time Memory
408463 2021-05-19T07:35:52 Z 8e7 Toy Train (IOI17_train) C++14
100 / 100
1033 ms 1752 KB
#include "train.h"
 
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#define ll long long
#define maxn 5005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int own[maxn], del[maxn];
vector<int> adj[maxn], rev[maxn];
vector<int> f(int a, vector<int> st, int n) {
	bool found[n];
	int deg[n];
	for (int i = 0;i < n;i++){ 
		found[i] = 0;
		deg[i] = 0;
		for (int j:adj[i]) {
			if (!del[j]) deg[i]++;
		}
	}
	
	queue<int> que;
	for (int i:st) {
		found[i] = 1;
		que.push(i);
	}	
	while (que.size()) {
		int cur = que.front();que.pop();
		found[cur] = 1;
		for (int v:rev[cur]) {
			if (found[v] || del[v]) continue;
			deg[v]--;
			if (own[v] == a || deg[v] == 0) {
				found[v] = 1;
				que.push(v);
			}
		}
	}
	vector<int> ret (n, 0);
	for (int i = 0;i < n;i++) ret[i] = found[i] ? 1 : 0;
	return ret;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	int n = a.size(), m = u.size();
	vector<int> b;
	for (int i = 0;i < n;i++){
		own[i] = a[i];
		if (r[i]) b.push_back(i);
	}
	for (int i = 0;i < m;i++) {
		adj[u[i]].push_back(v[i]);
		rev[v[i]].push_back(u[i]);
	}
	vector<int> ret(n, 0);
	while (true) {
		vector<int> fa = f(1, b, n);
		vector<int> t;
		for (int i = 0;i < n;i++) {
			if (!fa[i] && !del[i]) t.push_back(i);
		}
		//cout << endl;
		//for (int i:t) cout << i << " ";
		//cout << endl;
		vector<int> fb = f(0, t, n);
		int found = 0;
		for (int i = 0;i < n;i++) {
			if (fb[i]) {
				found = 1;
				del[i] = 1;
			}
		}
		if (!found) {
			for (int i = 0;i < n;i++) {
				if (fa[i]) ret[i] = 1;
			}
			break;
		}
		vector<int> tmp;
		for (int i:b) {
			if (!del[i]) tmp.push_back(i);
		}
		b = tmp;
	}
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1100 KB Output is correct
2 Correct 8 ms 1220 KB Output is correct
3 Correct 8 ms 1228 KB Output is correct
4 Correct 7 ms 1204 KB Output is correct
5 Correct 9 ms 1228 KB Output is correct
6 Correct 7 ms 1264 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 10 ms 1268 KB Output is correct
9 Correct 9 ms 1228 KB Output is correct
10 Correct 7 ms 1228 KB Output is correct
11 Correct 5 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 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 2 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 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 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 1524 KB Output is correct
2 Correct 295 ms 1524 KB Output is correct
3 Correct 424 ms 1716 KB Output is correct
4 Correct 10 ms 1584 KB Output is correct
5 Correct 12 ms 1580 KB Output is correct
6 Correct 18 ms 1580 KB Output is correct
7 Correct 11 ms 1576 KB Output is correct
8 Correct 12 ms 1708 KB Output is correct
9 Correct 12 ms 1612 KB Output is correct
10 Correct 10 ms 1612 KB Output is correct
11 Correct 12 ms 1560 KB Output is correct
12 Correct 11 ms 1612 KB Output is correct
13 Correct 12 ms 1584 KB Output is correct
14 Correct 10 ms 1656 KB Output is correct
15 Correct 10 ms 1556 KB Output is correct
16 Correct 9 ms 1612 KB Output is correct
17 Correct 11 ms 1580 KB Output is correct
18 Correct 455 ms 1360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1444 KB Output is correct
2 Correct 12 ms 1448 KB Output is correct
3 Correct 12 ms 1716 KB Output is correct
4 Correct 10 ms 1708 KB Output is correct
5 Correct 11 ms 1612 KB Output is correct
6 Correct 25 ms 1564 KB Output is correct
7 Correct 10 ms 1656 KB Output is correct
8 Correct 13 ms 1612 KB Output is correct
9 Correct 13 ms 1668 KB Output is correct
10 Correct 12 ms 1612 KB Output is correct
11 Correct 11 ms 1752 KB Output is correct
12 Correct 11 ms 1612 KB Output is correct
13 Correct 10 ms 1704 KB Output is correct
14 Correct 10 ms 1572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1484 KB Output is correct
2 Correct 9 ms 1356 KB Output is correct
3 Correct 10 ms 1484 KB Output is correct
4 Correct 9 ms 1356 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 5 ms 1100 KB Output is correct
7 Correct 6 ms 1100 KB Output is correct
8 Correct 7 ms 1072 KB Output is correct
9 Correct 7 ms 1100 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 7 ms 1056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1100 KB Output is correct
2 Correct 8 ms 1220 KB Output is correct
3 Correct 8 ms 1228 KB Output is correct
4 Correct 7 ms 1204 KB Output is correct
5 Correct 9 ms 1228 KB Output is correct
6 Correct 7 ms 1264 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 10 ms 1268 KB Output is correct
9 Correct 9 ms 1228 KB Output is correct
10 Correct 7 ms 1228 KB Output is correct
11 Correct 5 ms 1228 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 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 2 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 540 KB Output is correct
32 Correct 150 ms 1524 KB Output is correct
33 Correct 295 ms 1524 KB Output is correct
34 Correct 424 ms 1716 KB Output is correct
35 Correct 10 ms 1584 KB Output is correct
36 Correct 12 ms 1580 KB Output is correct
37 Correct 18 ms 1580 KB Output is correct
38 Correct 11 ms 1576 KB Output is correct
39 Correct 12 ms 1708 KB Output is correct
40 Correct 12 ms 1612 KB Output is correct
41 Correct 10 ms 1612 KB Output is correct
42 Correct 12 ms 1560 KB Output is correct
43 Correct 11 ms 1612 KB Output is correct
44 Correct 12 ms 1584 KB Output is correct
45 Correct 10 ms 1656 KB Output is correct
46 Correct 10 ms 1556 KB Output is correct
47 Correct 9 ms 1612 KB Output is correct
48 Correct 11 ms 1580 KB Output is correct
49 Correct 455 ms 1360 KB Output is correct
50 Correct 11 ms 1444 KB Output is correct
51 Correct 12 ms 1448 KB Output is correct
52 Correct 12 ms 1716 KB Output is correct
53 Correct 10 ms 1708 KB Output is correct
54 Correct 11 ms 1612 KB Output is correct
55 Correct 25 ms 1564 KB Output is correct
56 Correct 10 ms 1656 KB Output is correct
57 Correct 13 ms 1612 KB Output is correct
58 Correct 13 ms 1668 KB Output is correct
59 Correct 12 ms 1612 KB Output is correct
60 Correct 11 ms 1752 KB Output is correct
61 Correct 11 ms 1612 KB Output is correct
62 Correct 10 ms 1704 KB Output is correct
63 Correct 10 ms 1572 KB Output is correct
64 Correct 10 ms 1484 KB Output is correct
65 Correct 9 ms 1356 KB Output is correct
66 Correct 10 ms 1484 KB Output is correct
67 Correct 9 ms 1356 KB Output is correct
68 Correct 2 ms 588 KB Output is correct
69 Correct 5 ms 1100 KB Output is correct
70 Correct 6 ms 1100 KB Output is correct
71 Correct 7 ms 1072 KB Output is correct
72 Correct 7 ms 1100 KB Output is correct
73 Correct 3 ms 716 KB Output is correct
74 Correct 7 ms 1056 KB Output is correct
75 Correct 225 ms 1672 KB Output is correct
76 Correct 323 ms 1720 KB Output is correct
77 Correct 492 ms 1740 KB Output is correct
78 Correct 530 ms 1724 KB Output is correct
79 Correct 453 ms 1724 KB Output is correct
80 Correct 10 ms 1576 KB Output is correct
81 Correct 11 ms 1620 KB Output is correct
82 Correct 13 ms 1612 KB Output is correct
83 Correct 14 ms 1584 KB Output is correct
84 Correct 16 ms 1612 KB Output is correct
85 Correct 13 ms 1584 KB Output is correct
86 Correct 18 ms 1612 KB Output is correct
87 Correct 14 ms 1708 KB Output is correct
88 Correct 16 ms 1612 KB Output is correct
89 Correct 12 ms 1612 KB Output is correct
90 Correct 23 ms 1748 KB Output is correct
91 Correct 19 ms 1692 KB Output is correct
92 Correct 38 ms 1712 KB Output is correct
93 Correct 41 ms 1612 KB Output is correct
94 Correct 38 ms 1684 KB Output is correct
95 Correct 38 ms 1568 KB Output is correct
96 Correct 109 ms 1616 KB Output is correct
97 Correct 627 ms 1732 KB Output is correct
98 Correct 918 ms 1672 KB Output is correct
99 Correct 1033 ms 1664 KB Output is correct
100 Correct 464 ms 1324 KB Output is correct