Submission #118272

# Submission time Handle Problem Language Result Execution time Memory
118272 2019-06-18T14:00:42 Z MvC Toy Train (IOI17_train) C++14
100 / 100
395 ms 8384 KB
// .... .... .....!
// ...... ......!
// .... ....... ..... ..!
// ...... ... ... .... ... .... .....!
// ... .. ... .... ...?

#include "train.h"
#include <vector>
#include <algorithm>
using namespace std;

#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; i++)
#define fer(i, x, n) for (int i = (int)(x), _n = (int)(n); i < _n; i++)
#define rof(i, n, x) for (int i = (int)(n), _x = (int)(x); i-- > _x; )
#define sz(x) (int((x).size()))
#define pb push_back
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second

template<class P, class Q> inline void smin(P &a, Q b) { if (b < a) a = b; }
template<class P, class Q> inline void smax(P &a, Q b) { if (a < b) a = b; }

typedef long long ll;
typedef pair<int, int> pii;

////////////////////////////////////////////////////////////////////////////////

const int maxn = 300000 + 100;

vector<int> radj[maxn];
int deg[maxn], need[maxn];

void dfs(int u, vector<int> &w) {
	for(int v: radj[u]) {
		need[v]--;
		if(!w[v] && need[v] == 0) dfs(v, w); // only dfs through non-charging vertices
	}
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	int n = sz(a);
	rep(i, sz(u)) radj[v[i]].pb(u[i]), deg[u[i]]++;
	vector<int> res(n, 1);
	for(bool cng = true; !(cng = !cng); ) {
		rep(i, n) need[i] = (a[i] ? 1 : deg[i]); // d only matters here
		rep(i, n) if(r[i] && res[i]) dfs(i, r); // dfs from yet-has-a-chance-to-win wells
		rep(i, n) if(r[i] && res[i] && need[i] > 0) res[i] = false, cng = true; // and see if they had no chance
	}
	rep(i, n) res[i] &= (need[i] <= 0); // look, more fopdoodles
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7808 KB Output is correct
2 Correct 13 ms 7808 KB Output is correct
3 Correct 13 ms 7792 KB Output is correct
4 Correct 13 ms 7812 KB Output is correct
5 Correct 12 ms 7844 KB Output is correct
6 Correct 12 ms 7808 KB Output is correct
7 Correct 12 ms 7808 KB Output is correct
8 Correct 11 ms 7808 KB Output is correct
9 Correct 11 ms 7680 KB Output is correct
10 Correct 10 ms 7680 KB Output is correct
11 Correct 11 ms 7680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 8 ms 7296 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7344 KB Output is correct
5 Correct 8 ms 7296 KB Output is correct
6 Correct 8 ms 7296 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 8 ms 7344 KB Output is correct
10 Correct 7 ms 7296 KB Output is correct
11 Correct 7 ms 7296 KB Output is correct
12 Correct 8 ms 7396 KB Output is correct
13 Correct 8 ms 7384 KB Output is correct
14 Correct 8 ms 7396 KB Output is correct
15 Correct 7 ms 7296 KB Output is correct
16 Correct 7 ms 7296 KB Output is correct
17 Correct 7 ms 7424 KB Output is correct
18 Correct 8 ms 7296 KB Output is correct
19 Correct 7 ms 7296 KB Output is correct
20 Correct 7 ms 7296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8200 KB Output is correct
2 Correct 127 ms 8344 KB Output is correct
3 Correct 195 ms 8292 KB Output is correct
4 Correct 14 ms 8240 KB Output is correct
5 Correct 19 ms 8320 KB Output is correct
6 Correct 16 ms 8292 KB Output is correct
7 Correct 15 ms 8188 KB Output is correct
8 Correct 14 ms 8192 KB Output is correct
9 Correct 14 ms 8192 KB Output is correct
10 Correct 14 ms 8192 KB Output is correct
11 Correct 13 ms 8164 KB Output is correct
12 Correct 13 ms 8064 KB Output is correct
13 Correct 14 ms 8312 KB Output is correct
14 Correct 15 ms 8320 KB Output is correct
15 Correct 15 ms 8316 KB Output is correct
16 Correct 14 ms 8320 KB Output is correct
17 Correct 14 ms 8284 KB Output is correct
18 Correct 286 ms 7968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7936 KB Output is correct
2 Correct 14 ms 8112 KB Output is correct
3 Correct 14 ms 8192 KB Output is correct
4 Correct 15 ms 8320 KB Output is correct
5 Correct 14 ms 8184 KB Output is correct
6 Correct 14 ms 8192 KB Output is correct
7 Correct 15 ms 8196 KB Output is correct
8 Correct 13 ms 8192 KB Output is correct
9 Correct 14 ms 8148 KB Output is correct
10 Correct 14 ms 8192 KB Output is correct
11 Correct 15 ms 8192 KB Output is correct
12 Correct 14 ms 8256 KB Output is correct
13 Correct 14 ms 8192 KB Output is correct
14 Correct 13 ms 8152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8064 KB Output is correct
2 Correct 15 ms 8384 KB Output is correct
3 Correct 14 ms 8320 KB Output is correct
4 Correct 14 ms 8192 KB Output is correct
5 Correct 7 ms 7424 KB Output is correct
6 Correct 10 ms 7840 KB Output is correct
7 Correct 12 ms 7936 KB Output is correct
8 Correct 12 ms 8060 KB Output is correct
9 Correct 12 ms 7936 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 11 ms 7936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7808 KB Output is correct
2 Correct 13 ms 7808 KB Output is correct
3 Correct 13 ms 7792 KB Output is correct
4 Correct 13 ms 7812 KB Output is correct
5 Correct 12 ms 7844 KB Output is correct
6 Correct 12 ms 7808 KB Output is correct
7 Correct 12 ms 7808 KB Output is correct
8 Correct 11 ms 7808 KB Output is correct
9 Correct 11 ms 7680 KB Output is correct
10 Correct 10 ms 7680 KB Output is correct
11 Correct 11 ms 7680 KB Output is correct
12 Correct 8 ms 7424 KB Output is correct
13 Correct 8 ms 7296 KB Output is correct
14 Correct 8 ms 7424 KB Output is correct
15 Correct 8 ms 7344 KB Output is correct
16 Correct 8 ms 7296 KB Output is correct
17 Correct 8 ms 7296 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 8 ms 7424 KB Output is correct
20 Correct 8 ms 7344 KB Output is correct
21 Correct 7 ms 7296 KB Output is correct
22 Correct 7 ms 7296 KB Output is correct
23 Correct 8 ms 7396 KB Output is correct
24 Correct 8 ms 7384 KB Output is correct
25 Correct 8 ms 7396 KB Output is correct
26 Correct 7 ms 7296 KB Output is correct
27 Correct 7 ms 7296 KB Output is correct
28 Correct 7 ms 7424 KB Output is correct
29 Correct 8 ms 7296 KB Output is correct
30 Correct 7 ms 7296 KB Output is correct
31 Correct 7 ms 7296 KB Output is correct
32 Correct 71 ms 8200 KB Output is correct
33 Correct 127 ms 8344 KB Output is correct
34 Correct 195 ms 8292 KB Output is correct
35 Correct 14 ms 8240 KB Output is correct
36 Correct 19 ms 8320 KB Output is correct
37 Correct 16 ms 8292 KB Output is correct
38 Correct 15 ms 8188 KB Output is correct
39 Correct 14 ms 8192 KB Output is correct
40 Correct 14 ms 8192 KB Output is correct
41 Correct 14 ms 8192 KB Output is correct
42 Correct 13 ms 8164 KB Output is correct
43 Correct 13 ms 8064 KB Output is correct
44 Correct 14 ms 8312 KB Output is correct
45 Correct 15 ms 8320 KB Output is correct
46 Correct 15 ms 8316 KB Output is correct
47 Correct 14 ms 8320 KB Output is correct
48 Correct 14 ms 8284 KB Output is correct
49 Correct 286 ms 7968 KB Output is correct
50 Correct 12 ms 7936 KB Output is correct
51 Correct 14 ms 8112 KB Output is correct
52 Correct 14 ms 8192 KB Output is correct
53 Correct 15 ms 8320 KB Output is correct
54 Correct 14 ms 8184 KB Output is correct
55 Correct 14 ms 8192 KB Output is correct
56 Correct 15 ms 8196 KB Output is correct
57 Correct 13 ms 8192 KB Output is correct
58 Correct 14 ms 8148 KB Output is correct
59 Correct 14 ms 8192 KB Output is correct
60 Correct 15 ms 8192 KB Output is correct
61 Correct 14 ms 8256 KB Output is correct
62 Correct 14 ms 8192 KB Output is correct
63 Correct 13 ms 8152 KB Output is correct
64 Correct 14 ms 8064 KB Output is correct
65 Correct 15 ms 8384 KB Output is correct
66 Correct 14 ms 8320 KB Output is correct
67 Correct 14 ms 8192 KB Output is correct
68 Correct 7 ms 7424 KB Output is correct
69 Correct 10 ms 7840 KB Output is correct
70 Correct 12 ms 7936 KB Output is correct
71 Correct 12 ms 8060 KB Output is correct
72 Correct 12 ms 7936 KB Output is correct
73 Correct 9 ms 7552 KB Output is correct
74 Correct 11 ms 7936 KB Output is correct
75 Correct 66 ms 8320 KB Output is correct
76 Correct 141 ms 8292 KB Output is correct
77 Correct 228 ms 8296 KB Output is correct
78 Correct 222 ms 8288 KB Output is correct
79 Correct 234 ms 8312 KB Output is correct
80 Correct 15 ms 8284 KB Output is correct
81 Correct 14 ms 8192 KB Output is correct
82 Correct 15 ms 8192 KB Output is correct
83 Correct 16 ms 8320 KB Output is correct
84 Correct 17 ms 8312 KB Output is correct
85 Correct 14 ms 8192 KB Output is correct
86 Correct 18 ms 8320 KB Output is correct
87 Correct 14 ms 8192 KB Output is correct
88 Correct 20 ms 8292 KB Output is correct
89 Correct 15 ms 8192 KB Output is correct
90 Correct 23 ms 8284 KB Output is correct
91 Correct 24 ms 8192 KB Output is correct
92 Correct 79 ms 8284 KB Output is correct
93 Correct 30 ms 8192 KB Output is correct
94 Correct 32 ms 8192 KB Output is correct
95 Correct 34 ms 8272 KB Output is correct
96 Correct 63 ms 8196 KB Output is correct
97 Correct 244 ms 8276 KB Output is correct
98 Correct 346 ms 8252 KB Output is correct
99 Correct 395 ms 8236 KB Output is correct
100 Correct 285 ms 7968 KB Output is correct