답안 #834313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834313 2023-08-22T12:58:20 Z KoD 장난감 기차 (IOI17_train) C++17
49 / 100
2000 ms 1300 KB
#include "train.h"

#include <array>
#include <algorithm>
#include <numeric>
#include <utility>
#include <iterator>
#include <iostream>
#include <cassert>
#include <tuple>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <map>

using std::array;
using std::tuple;
using std::pair;
using std::vector;
using std::string;

using ll = long long;
constexpr int inf = (1 << 30) - 1;
constexpr ll infll = (1ll << 62) - 1;

template <class T> bool setmin(T& x, const T& y) { return x > y && (x = y, true); }
template <class T> bool setmax(T& x, const T& y) { return x < y && (x = y, true); }

template <class F> struct make_fixed : private F {
    explicit make_fixed(F&& f) : F(std::forward<F>(f)) {}
    template <class... Args> decltype(auto) operator()(Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

vector<int> who_wins(vector<int> A, vector<int> R, vector<int> U, vector<int> V) {
	const int N = (int)A.size();
	const int M = (int)U.size();
	vector<int> ans(N);
	vector<char> alive(N, true);
	const auto bfs = [&](vector<int> set, int type) {
		vector<vector<int>> rG(N);
		vector<int> deg(N);
		for (int i = 0; i < M; ++i) {
			int u = U[i], v = V[i];
			if (alive[u] && alive[v]) {
				rG[v].push_back(u);
				deg[u] += 1;
			}
		}
		vector<char> reach(N);
		std::queue<int> que;
		for (const int u : set) {
			reach[u] = true;
			que.push(u);
		}
		while (!que.empty()) {
			const int u = que.front();
			que.pop();
			for (const int v : rG[u]) {
				if (reach[v]) continue;
				if (A[v] == type) {
					reach[v] = true;
					que.push(v);
				} else if (--deg[v] == 0) {
					reach[v] = true;
					que.push(v);
				}
			}
		}
		return reach;
	};
	while (std::any_of(alive.begin(), alive.end(), [](bool b) { return b; })) {
		vector<int> s;
		for (int i = 0; i < N; ++i) {
			if (alive[i] && R[i]) {
				s.push_back(i);
			}
		}
		auto s2 = bfs(std::move(s), 1);
		vector<int> t;
		for (int i = 0; i < N; ++i) {
			if (alive[i] && !s2[i]) {
				t.push_back(i);
			}
		}
		if (t.empty()) {
			for (int i = 0; i < N; ++i) {
				if (alive[i]) {
					ans[i] = 1;
					alive[i] = false;
				}
			}
			break;
		}
		auto t2 = bfs(std::move(t), 0);
		for (int i = 0; i < N; ++i) {
			if (t2[i]) {
				alive[i] = false;
			}
		}
	}
	return ans;
}

#ifndef EVAL
#include "grader.cpp"
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 852 KB Output is correct
2 Correct 7 ms 852 KB Output is correct
3 Correct 6 ms 852 KB Output is correct
4 Correct 6 ms 852 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 6 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 6 ms 820 KB Output is correct
9 Correct 4 ms 836 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 3 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 357 ms 1288 KB Output is correct
2 Correct 666 ms 1284 KB Output is correct
3 Correct 920 ms 1288 KB Output is correct
4 Correct 7 ms 1236 KB Output is correct
5 Correct 9 ms 1236 KB Output is correct
6 Correct 10 ms 1236 KB Output is correct
7 Correct 5 ms 1208 KB Output is correct
8 Correct 7 ms 1284 KB Output is correct
9 Correct 6 ms 1236 KB Output is correct
10 Correct 6 ms 1236 KB Output is correct
11 Correct 6 ms 1236 KB Output is correct
12 Correct 5 ms 1236 KB Output is correct
13 Correct 5 ms 1236 KB Output is correct
14 Correct 6 ms 1236 KB Output is correct
15 Correct 5 ms 1236 KB Output is correct
16 Correct 5 ms 1236 KB Output is correct
17 Correct 5 ms 1236 KB Output is correct
18 Correct 1425 ms 984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1108 KB Output is correct
2 Correct 6 ms 1108 KB Output is correct
3 Correct 7 ms 1248 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 6 ms 1236 KB Output is correct
6 Correct 6 ms 1236 KB Output is correct
7 Correct 7 ms 1236 KB Output is correct
8 Correct 6 ms 1236 KB Output is correct
9 Correct 6 ms 1236 KB Output is correct
10 Correct 5 ms 1236 KB Output is correct
11 Correct 5 ms 1236 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 10 ms 1236 KB Output is correct
14 Correct 8 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1236 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 7 ms 1236 KB Output is correct
4 Correct 5 ms 1096 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 4 ms 852 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 4 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 852 KB Output is correct
2 Correct 7 ms 852 KB Output is correct
3 Correct 6 ms 852 KB Output is correct
4 Correct 6 ms 852 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 6 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 6 ms 820 KB Output is correct
9 Correct 4 ms 836 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 3 ms 852 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 357 ms 1288 KB Output is correct
33 Correct 666 ms 1284 KB Output is correct
34 Correct 920 ms 1288 KB Output is correct
35 Correct 7 ms 1236 KB Output is correct
36 Correct 9 ms 1236 KB Output is correct
37 Correct 10 ms 1236 KB Output is correct
38 Correct 5 ms 1208 KB Output is correct
39 Correct 7 ms 1284 KB Output is correct
40 Correct 6 ms 1236 KB Output is correct
41 Correct 6 ms 1236 KB Output is correct
42 Correct 6 ms 1236 KB Output is correct
43 Correct 5 ms 1236 KB Output is correct
44 Correct 5 ms 1236 KB Output is correct
45 Correct 6 ms 1236 KB Output is correct
46 Correct 5 ms 1236 KB Output is correct
47 Correct 5 ms 1236 KB Output is correct
48 Correct 5 ms 1236 KB Output is correct
49 Correct 1425 ms 984 KB Output is correct
50 Correct 6 ms 1108 KB Output is correct
51 Correct 6 ms 1108 KB Output is correct
52 Correct 7 ms 1248 KB Output is correct
53 Correct 6 ms 1236 KB Output is correct
54 Correct 6 ms 1236 KB Output is correct
55 Correct 6 ms 1236 KB Output is correct
56 Correct 7 ms 1236 KB Output is correct
57 Correct 6 ms 1236 KB Output is correct
58 Correct 6 ms 1236 KB Output is correct
59 Correct 5 ms 1236 KB Output is correct
60 Correct 5 ms 1236 KB Output is correct
61 Correct 8 ms 1236 KB Output is correct
62 Correct 10 ms 1236 KB Output is correct
63 Correct 8 ms 1108 KB Output is correct
64 Correct 7 ms 1236 KB Output is correct
65 Correct 5 ms 1236 KB Output is correct
66 Correct 7 ms 1236 KB Output is correct
67 Correct 5 ms 1096 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 3 ms 852 KB Output is correct
70 Correct 4 ms 852 KB Output is correct
71 Correct 6 ms 852 KB Output is correct
72 Correct 4 ms 852 KB Output is correct
73 Correct 2 ms 468 KB Output is correct
74 Correct 4 ms 852 KB Output is correct
75 Correct 588 ms 1252 KB Output is correct
76 Correct 718 ms 1300 KB Output is correct
77 Correct 970 ms 1296 KB Output is correct
78 Correct 1010 ms 1288 KB Output is correct
79 Correct 957 ms 1288 KB Output is correct
80 Correct 7 ms 1236 KB Output is correct
81 Correct 12 ms 1296 KB Output is correct
82 Correct 9 ms 1236 KB Output is correct
83 Correct 10 ms 1236 KB Output is correct
84 Correct 13 ms 1284 KB Output is correct
85 Correct 8 ms 1236 KB Output is correct
86 Correct 14 ms 1236 KB Output is correct
87 Correct 7 ms 1236 KB Output is correct
88 Correct 18 ms 1288 KB Output is correct
89 Correct 10 ms 1236 KB Output is correct
90 Correct 31 ms 1264 KB Output is correct
91 Correct 28 ms 1236 KB Output is correct
92 Correct 70 ms 1272 KB Output is correct
93 Correct 62 ms 1236 KB Output is correct
94 Correct 65 ms 1272 KB Output is correct
95 Correct 68 ms 1268 KB Output is correct
96 Correct 315 ms 1192 KB Output is correct
97 Correct 1417 ms 1280 KB Output is correct
98 Execution timed out 2045 ms 1236 KB Time limit exceeded
99 Halted 0 ms 0 KB -