Submission #262138

# Submission time Handle Problem Language Result Execution time Memory
262138 2020-08-12T11:41:42 Z sjimed Toy Train (IOI17_train) C++14
100 / 100
934 ms 1912 KB
#include "train.h"
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define pre(a) cout << fixed; cout.precision(a)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define em emplace
#define eb emplace_back
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n, m;
vector<int> g[5010];
vector<int> rg[5010];
vector<int> w;
vector<int> A;

vector<bool> canGo(vector<int> &x, int c) {
	int deg[5010] = {};
	vector<bool> chk(n, 0);
	vector<int> ret;
	queue<int> q;

	for(int i=0; i<n; i++) {
		if(w[i] != -1) continue;

		for(int j : g[i]) 
			if(w[j] == -1) deg[i]++;
	}

	for(auto i : x) 
		chk[i] = true, q.em(i);

	while(q.size()) {
		int cur = q.front();
		q.pop();

		for(auto i : rg[cur]) {
			if(chk[i] || w[i] != -1) continue;
			if(A[i] == c) {
				chk[i] = true;
				q.em(i);
			}
			else {
				deg[i]--;
				if(deg[i] == 0) chk[i] = true, q.em(i);
			}
		}
	}

	for(int i=0; i<n; i++)
		if(chk[i]) ret.eb(i);

	return chk;
}

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	n = a.size();
	m = u.size();
	A = a;

	w.resize(n, -1);

	for(int i=0; i<m; i++) {
		g[u[i]].eb(v[i]);
		rg[v[i]].eb(u[i]);
	}

	int cnt = 1;
	while(cnt) {
		vector<int> x, y;
		for(int i=0; i<n; i++) 
			if(r[i] && w[i] == -1) x.eb(i);

		auto v = canGo(x, 1);

		for(int i=0; i<n; i++) 
			if(w[i] == -1 && !v[i]) y.eb(i);

		if(y.empty()) {
			for(int i=0; i<n; i++) 
				if(w[i] == -1) w[i] = 1;
			
			break;
		}
		else {
			v = canGo(y, 0);
			for(int i=0; i<n; i++) 
				if(v[i]) w[i] = 0;
		}
	}

	return w;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1280 KB Output is correct
2 Correct 7 ms 1280 KB Output is correct
3 Correct 8 ms 1280 KB Output is correct
4 Correct 8 ms 1280 KB Output is correct
5 Correct 8 ms 1280 KB Output is correct
6 Correct 6 ms 1280 KB Output is correct
7 Correct 6 ms 1280 KB Output is correct
8 Correct 7 ms 1280 KB Output is correct
9 Correct 6 ms 1280 KB Output is correct
10 Correct 6 ms 1152 KB Output is correct
11 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 1912 KB Output is correct
2 Correct 351 ms 1784 KB Output is correct
3 Correct 481 ms 1784 KB Output is correct
4 Correct 12 ms 1664 KB Output is correct
5 Correct 12 ms 1664 KB Output is correct
6 Correct 12 ms 1664 KB Output is correct
7 Correct 10 ms 1792 KB Output is correct
8 Correct 10 ms 1664 KB Output is correct
9 Correct 10 ms 1664 KB Output is correct
10 Correct 10 ms 1664 KB Output is correct
11 Correct 10 ms 1664 KB Output is correct
12 Correct 9 ms 1664 KB Output is correct
13 Correct 10 ms 1664 KB Output is correct
14 Correct 10 ms 1664 KB Output is correct
15 Correct 10 ms 1664 KB Output is correct
16 Correct 10 ms 1664 KB Output is correct
17 Correct 10 ms 1664 KB Output is correct
18 Correct 600 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1536 KB Output is correct
2 Correct 10 ms 1536 KB Output is correct
3 Correct 10 ms 1664 KB Output is correct
4 Correct 11 ms 1664 KB Output is correct
5 Correct 11 ms 1664 KB Output is correct
6 Correct 10 ms 1664 KB Output is correct
7 Correct 11 ms 1664 KB Output is correct
8 Correct 10 ms 1664 KB Output is correct
9 Correct 11 ms 1664 KB Output is correct
10 Correct 12 ms 1664 KB Output is correct
11 Correct 14 ms 1792 KB Output is correct
12 Correct 12 ms 1664 KB Output is correct
13 Correct 11 ms 1664 KB Output is correct
14 Correct 10 ms 1512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1664 KB Output is correct
2 Correct 10 ms 1664 KB Output is correct
3 Correct 11 ms 1664 KB Output is correct
4 Correct 9 ms 1536 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 7 ms 1280 KB Output is correct
7 Correct 7 ms 1280 KB Output is correct
8 Correct 7 ms 1280 KB Output is correct
9 Correct 7 ms 1280 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 6 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1280 KB Output is correct
2 Correct 7 ms 1280 KB Output is correct
3 Correct 8 ms 1280 KB Output is correct
4 Correct 8 ms 1280 KB Output is correct
5 Correct 8 ms 1280 KB Output is correct
6 Correct 6 ms 1280 KB Output is correct
7 Correct 6 ms 1280 KB Output is correct
8 Correct 7 ms 1280 KB Output is correct
9 Correct 6 ms 1280 KB Output is correct
10 Correct 6 ms 1152 KB Output is correct
11 Correct 5 ms 1152 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 172 ms 1912 KB Output is correct
33 Correct 351 ms 1784 KB Output is correct
34 Correct 481 ms 1784 KB Output is correct
35 Correct 12 ms 1664 KB Output is correct
36 Correct 12 ms 1664 KB Output is correct
37 Correct 12 ms 1664 KB Output is correct
38 Correct 10 ms 1792 KB Output is correct
39 Correct 10 ms 1664 KB Output is correct
40 Correct 10 ms 1664 KB Output is correct
41 Correct 10 ms 1664 KB Output is correct
42 Correct 10 ms 1664 KB Output is correct
43 Correct 9 ms 1664 KB Output is correct
44 Correct 10 ms 1664 KB Output is correct
45 Correct 10 ms 1664 KB Output is correct
46 Correct 10 ms 1664 KB Output is correct
47 Correct 10 ms 1664 KB Output is correct
48 Correct 10 ms 1664 KB Output is correct
49 Correct 600 ms 1400 KB Output is correct
50 Correct 8 ms 1536 KB Output is correct
51 Correct 10 ms 1536 KB Output is correct
52 Correct 10 ms 1664 KB Output is correct
53 Correct 11 ms 1664 KB Output is correct
54 Correct 11 ms 1664 KB Output is correct
55 Correct 10 ms 1664 KB Output is correct
56 Correct 11 ms 1664 KB Output is correct
57 Correct 10 ms 1664 KB Output is correct
58 Correct 11 ms 1664 KB Output is correct
59 Correct 12 ms 1664 KB Output is correct
60 Correct 14 ms 1792 KB Output is correct
61 Correct 12 ms 1664 KB Output is correct
62 Correct 11 ms 1664 KB Output is correct
63 Correct 10 ms 1512 KB Output is correct
64 Correct 13 ms 1664 KB Output is correct
65 Correct 10 ms 1664 KB Output is correct
66 Correct 11 ms 1664 KB Output is correct
67 Correct 9 ms 1536 KB Output is correct
68 Correct 1 ms 640 KB Output is correct
69 Correct 7 ms 1280 KB Output is correct
70 Correct 7 ms 1280 KB Output is correct
71 Correct 7 ms 1280 KB Output is correct
72 Correct 7 ms 1280 KB Output is correct
73 Correct 2 ms 768 KB Output is correct
74 Correct 6 ms 1152 KB Output is correct
75 Correct 271 ms 1664 KB Output is correct
76 Correct 365 ms 1680 KB Output is correct
77 Correct 513 ms 1664 KB Output is correct
78 Correct 516 ms 1772 KB Output is correct
79 Correct 516 ms 1764 KB Output is correct
80 Correct 11 ms 1664 KB Output is correct
81 Correct 11 ms 1664 KB Output is correct
82 Correct 12 ms 1664 KB Output is correct
83 Correct 12 ms 1664 KB Output is correct
84 Correct 14 ms 1664 KB Output is correct
85 Correct 12 ms 1792 KB Output is correct
86 Correct 13 ms 1664 KB Output is correct
87 Correct 12 ms 1664 KB Output is correct
88 Correct 16 ms 1664 KB Output is correct
89 Correct 11 ms 1664 KB Output is correct
90 Correct 21 ms 1664 KB Output is correct
91 Correct 21 ms 1664 KB Output is correct
92 Correct 36 ms 1668 KB Output is correct
93 Correct 35 ms 1664 KB Output is correct
94 Correct 34 ms 1664 KB Output is correct
95 Correct 42 ms 1664 KB Output is correct
96 Correct 112 ms 1656 KB Output is correct
97 Correct 584 ms 1784 KB Output is correct
98 Correct 885 ms 1712 KB Output is correct
99 Correct 934 ms 1664 KB Output is correct
100 Correct 605 ms 1392 KB Output is correct