답안 #536340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536340 2022-03-13T01:41:57 Z skittles1412 장난감 기차 (IOI17_train) C++17
100 / 100
501 ms 1364 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...) 1412
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

const int maxn = 5000;

int n, m;
bool vis[maxn];
vector<int> own, dep, igraph[maxn];

vector<int> reachable(const vector<int>& arr, int side) {
	vector<int> dep = ::dep;

	bool qd[n]{};
	vector<int> q;
	auto push = [&](int u, bool f = false) -> void {
		if (!qd[u] && (f || !dep[u])) {
			qd[u] = true;
			q.push_back(u);
		}
	};

	for (int i = 0; i < n; i++) {
		if (!vis[i] && arr[i]) {
			push(i, true);
		}
	}

	vector<int> ans(n);
	while (sz(q)) {
		int u = q.back();
		q.pop_back();

		ans[u] = true;

		for (auto& v : igraph[u]) {
			if (!vis[v]) {
				dep[v]--;
				if (own[v] == side) {
					push(v, true);
				} else {
					push(v);
				}
			}
		}
	}

	return ans;
}

vector<int> who_wins(vector<int> own,
					 vector<int> charging,
					 vector<int> us,
					 vector<int> vs) {
	::own = own;
	n = sz(own);
	m = sz(us);

	for (int i = 0; i < m; i++) {
		int u = us[i], v = vs[i];
		igraph[v].push_back(u);
	}

	dep.resize(n);
	for (auto& a : us) {
		dep[a]++;
	}

	while (true) {
		vector<int> cur = reachable(charging, 1);
		for (auto& a : cur) {
			a ^= 1;
		}
		vector<int> nxt = reachable(cur, 0);

		int sz = 0;
		for (int i = 0; i < n; i++) {
			if (nxt[i]) {
				vis[i] = true;
				for (int j = 0; j < m; j++) {
					if (i == vs[j]) {
						dep[us[j]]--;
					}
				}
				sz++;
			}
		}

		if (!sz) {
			break;
		}
	}

	return reachable(charging, 1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 852 KB Output is correct
2 Correct 17 ms 964 KB Output is correct
3 Correct 18 ms 852 KB Output is correct
4 Correct 19 ms 952 KB Output is correct
5 Correct 19 ms 980 KB Output is correct
6 Correct 27 ms 948 KB Output is correct
7 Correct 26 ms 956 KB Output is correct
8 Correct 7 ms 944 KB Output is correct
9 Correct 18 ms 836 KB Output is correct
10 Correct 16 ms 924 KB Output is correct
11 Correct 13 ms 936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 424 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 420 KB Output is correct
6 Correct 1 ms 420 KB Output is correct
7 Correct 1 ms 424 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 412 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 424 KB Output is correct
16 Correct 1 ms 424 KB Output is correct
17 Correct 1 ms 420 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 1340 KB Output is correct
2 Correct 237 ms 1344 KB Output is correct
3 Correct 292 ms 1356 KB Output is correct
4 Correct 7 ms 1332 KB Output is correct
5 Correct 33 ms 1320 KB Output is correct
6 Correct 75 ms 1328 KB Output is correct
7 Correct 7 ms 1236 KB Output is correct
8 Correct 46 ms 1344 KB Output is correct
9 Correct 73 ms 1236 KB Output is correct
10 Correct 25 ms 1288 KB Output is correct
11 Correct 37 ms 1292 KB Output is correct
12 Correct 69 ms 1260 KB Output is correct
13 Correct 7 ms 1360 KB Output is correct
14 Correct 7 ms 1324 KB Output is correct
15 Correct 10 ms 1364 KB Output is correct
16 Correct 8 ms 1332 KB Output is correct
17 Correct 8 ms 1236 KB Output is correct
18 Correct 307 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1108 KB Output is correct
2 Correct 24 ms 1240 KB Output is correct
3 Correct 77 ms 1336 KB Output is correct
4 Correct 83 ms 1340 KB Output is correct
5 Correct 54 ms 1336 KB Output is correct
6 Correct 27 ms 1320 KB Output is correct
7 Correct 34 ms 1300 KB Output is correct
8 Correct 68 ms 1296 KB Output is correct
9 Correct 21 ms 1248 KB Output is correct
10 Correct 6 ms 1340 KB Output is correct
11 Correct 7 ms 1364 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 44 ms 1348 KB Output is correct
14 Correct 25 ms 1256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1336 KB Output is correct
2 Correct 7 ms 1236 KB Output is correct
3 Correct 30 ms 1344 KB Output is correct
4 Correct 7 ms 1236 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 28 ms 848 KB Output is correct
7 Correct 6 ms 1056 KB Output is correct
8 Correct 12 ms 948 KB Output is correct
9 Correct 8 ms 980 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 6 ms 920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 852 KB Output is correct
2 Correct 17 ms 964 KB Output is correct
3 Correct 18 ms 852 KB Output is correct
4 Correct 19 ms 952 KB Output is correct
5 Correct 19 ms 980 KB Output is correct
6 Correct 27 ms 948 KB Output is correct
7 Correct 26 ms 956 KB Output is correct
8 Correct 7 ms 944 KB Output is correct
9 Correct 18 ms 836 KB Output is correct
10 Correct 16 ms 924 KB Output is correct
11 Correct 13 ms 936 KB Output is correct
12 Correct 1 ms 424 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 420 KB Output is correct
17 Correct 1 ms 420 KB Output is correct
18 Correct 1 ms 424 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 412 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 424 KB Output is correct
27 Correct 1 ms 424 KB Output is correct
28 Correct 1 ms 420 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 416 KB Output is correct
32 Correct 167 ms 1340 KB Output is correct
33 Correct 237 ms 1344 KB Output is correct
34 Correct 292 ms 1356 KB Output is correct
35 Correct 7 ms 1332 KB Output is correct
36 Correct 33 ms 1320 KB Output is correct
37 Correct 75 ms 1328 KB Output is correct
38 Correct 7 ms 1236 KB Output is correct
39 Correct 46 ms 1344 KB Output is correct
40 Correct 73 ms 1236 KB Output is correct
41 Correct 25 ms 1288 KB Output is correct
42 Correct 37 ms 1292 KB Output is correct
43 Correct 69 ms 1260 KB Output is correct
44 Correct 7 ms 1360 KB Output is correct
45 Correct 7 ms 1324 KB Output is correct
46 Correct 10 ms 1364 KB Output is correct
47 Correct 8 ms 1332 KB Output is correct
48 Correct 8 ms 1236 KB Output is correct
49 Correct 307 ms 1024 KB Output is correct
50 Correct 6 ms 1108 KB Output is correct
51 Correct 24 ms 1240 KB Output is correct
52 Correct 77 ms 1336 KB Output is correct
53 Correct 83 ms 1340 KB Output is correct
54 Correct 54 ms 1336 KB Output is correct
55 Correct 27 ms 1320 KB Output is correct
56 Correct 34 ms 1300 KB Output is correct
57 Correct 68 ms 1296 KB Output is correct
58 Correct 21 ms 1248 KB Output is correct
59 Correct 6 ms 1340 KB Output is correct
60 Correct 7 ms 1364 KB Output is correct
61 Correct 6 ms 1236 KB Output is correct
62 Correct 44 ms 1348 KB Output is correct
63 Correct 25 ms 1256 KB Output is correct
64 Correct 41 ms 1336 KB Output is correct
65 Correct 7 ms 1236 KB Output is correct
66 Correct 30 ms 1344 KB Output is correct
67 Correct 7 ms 1236 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 28 ms 848 KB Output is correct
70 Correct 6 ms 1056 KB Output is correct
71 Correct 12 ms 948 KB Output is correct
72 Correct 8 ms 980 KB Output is correct
73 Correct 2 ms 596 KB Output is correct
74 Correct 6 ms 920 KB Output is correct
75 Correct 192 ms 1288 KB Output is correct
76 Correct 226 ms 1352 KB Output is correct
77 Correct 298 ms 1340 KB Output is correct
78 Correct 294 ms 1340 KB Output is correct
79 Correct 283 ms 1344 KB Output is correct
80 Correct 8 ms 1236 KB Output is correct
81 Correct 63 ms 1356 KB Output is correct
82 Correct 46 ms 1328 KB Output is correct
83 Correct 31 ms 1336 KB Output is correct
84 Correct 42 ms 1324 KB Output is correct
85 Correct 77 ms 1316 KB Output is correct
86 Correct 56 ms 1336 KB Output is correct
87 Correct 82 ms 1332 KB Output is correct
88 Correct 92 ms 1236 KB Output is correct
89 Correct 50 ms 1340 KB Output is correct
90 Correct 82 ms 1316 KB Output is correct
91 Correct 82 ms 1236 KB Output is correct
92 Correct 70 ms 1340 KB Output is correct
93 Correct 74 ms 1304 KB Output is correct
94 Correct 78 ms 1332 KB Output is correct
95 Correct 69 ms 1332 KB Output is correct
96 Correct 81 ms 1204 KB Output is correct
97 Correct 304 ms 1332 KB Output is correct
98 Correct 450 ms 1304 KB Output is correct
99 Correct 501 ms 1288 KB Output is correct
100 Correct 290 ms 1020 KB Output is correct