답안 #371302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
371302 2021-02-26T12:31:44 Z KoD 장난감 기차 (IOI17_train) C++17
16 / 100
14 ms 2412 KB
#include <bits/stdc++.h>
#include "train.h"

template <class T>
using Vec = std::vector<T>;

Vec<int> who_wins(Vec<int> a, Vec<int> r, Vec<int> u, Vec<int> v) {
	const int n = (int) a.size();
	const int m = (int) u.size();
	Vec<bool> loop(n);
	{
		bool sub1 = true;
		Vec<bool> right(n);
		for (int i = 0; i < m; ++i) {
			if (u[i] == v[i]) {
				loop[u[i]] = true;
			}
			else if (u[i] + 1 == v[i]) {
				right[u[i]] = true;
			}
			else {
				sub1 = false;
			}
		}
		if (sub1) {
			Vec<int> ret(n);
			for (int i = n - 1; i >= 0; --i) {
				if (a[i]) {
					ret[i] = 0;
					if (r[i] && loop[i]) {
						ret[i] = 1;
					}
					if (right[i] && ret[i + 1]) {
						ret[i] = 1;
					}
				}
				else {
					ret[i] = 1;
					if (!r[i] && loop[i]) {
						ret[i] = 0;
					}
					if (right[i] && !ret[i + 1]) {
						ret[i] = 0;
					}
				}
			}
			return ret;
		}
	}
	Vec<Vec<int>> graph(n);
	Vec<Vec<int>> revgraph(n);
	for (int i = 0; i < m; ++i) {
		graph[u[i]].push_back(v[i]);
		revgraph[v[i]].push_back(u[i]);
	}
	Vec<int> order;
	Vec<char> done(n);
	auto dfs1 = [&](auto dfs1, const int u) -> void {
		if (done[u]) {
			return;
		}
		done[u] = true;
		for (const auto v: graph[u]) {
			dfs1(dfs1, v);
		}
		order.push_back(u);
	};
	for (int i = 0; i < n; ++i) {
		dfs1(dfs1, i);
	}
	std::fill(done.begin(), done.end(), false);
	Vec<Vec<int>> group;
	auto dfs2 = [&](auto dfs2, const int u) -> void {
		if (done[u]) {
			return;
		}
		done[u] = true;
		group.back().push_back(u);
		for (const int v: revgraph[u]) {
			dfs2(dfs2, v);
		}
	};
	while (!order.empty()) {
		const auto u = order.back();
		order.pop_back();
		if (!done[u]) {
			group.push_back({ });
			dfs2(dfs2, u);
		}
	}
	const int g = (int) group.size();
	Vec<int> belong(n);
	for (int i = 0; i < g; ++i) {
		for (const auto u: group[i]) {
		belong[u] = i;
		}
	}
	Vec<Vec<int>> newgraph(g);
	for (int i = 0; i < m; ++i) {
		const auto x = belong[u[i]];
		const auto y = belong[v[i]];
		if (x != y) {
			newgraph[x].push_back(y);
		}
	}
	Vec<int> ok(g);
	for (int i = g - 1; i >= 0; --i) {
		if (group[i].size() >= 2) {
			for (const auto x: group[i]) {
				if (r[x]) {
					ok[i] = true;
				}
			}
		}
		for (const auto x: group[i]) {
			if (loop[x] && r[x]) {
			ok[i] = true;
			}
		}
		for (const auto y: newgraph[i]) {
			if (ok[y]) {
				ok[i] = true;
			}
		}
	}
	Vec<int> ret(n);
	for (int i = 0; i < n; ++i) {
		ret[i] = ok[belong[i]];
	}
	return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 4 ms 492 KB Output is correct
5 Correct 5 ms 492 KB Output is correct
6 Correct 4 ms 492 KB Output is correct
7 Correct 4 ms 492 KB Output is correct
8 Correct 4 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 5 ms 492 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB 3rd lines differ - on the 8th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2284 KB Output is correct
2 Correct 10 ms 2412 KB Output is correct
3 Correct 9 ms 2284 KB Output is correct
4 Correct 10 ms 2028 KB Output is correct
5 Correct 11 ms 2028 KB Output is correct
6 Correct 13 ms 1900 KB Output is correct
7 Correct 10 ms 1772 KB Output is correct
8 Correct 10 ms 1772 KB Output is correct
9 Correct 9 ms 1772 KB Output is correct
10 Correct 10 ms 1772 KB Output is correct
11 Correct 10 ms 1772 KB Output is correct
12 Correct 10 ms 2036 KB Output is correct
13 Correct 14 ms 1920 KB Output is correct
14 Correct 10 ms 1900 KB Output is correct
15 Correct 10 ms 2028 KB Output is correct
16 Correct 10 ms 1900 KB Output is correct
17 Correct 10 ms 1900 KB Output is correct
18 Correct 8 ms 1908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1516 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1644 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 4 ms 492 KB Output is correct
5 Correct 5 ms 492 KB Output is correct
6 Correct 4 ms 492 KB Output is correct
7 Correct 4 ms 492 KB Output is correct
8 Correct 4 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 5 ms 492 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Incorrect 1 ms 364 KB 3rd lines differ - on the 8th token, expected: '0', found: '1'
13 Halted 0 ms 0 KB -