답안 #45492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45492 2018-04-14T12:12:23 Z Abelyan 장난감 기차 (IOI17_train) C++17
49 / 100
2000 ms 1852 KB
#include "train.h"
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <queue>

#pragma GCC optimize("unroll-loops")
using namespace std;

const int N = 5006;
int n, m;
vector<int> g[N],ing[N];
bool col[N],chrg[N];


void rev(vector<bool> &s, vector<bool> &ans){
	for (int i = 0; i < n; i++){
		if (s[i] == 0) ans[i]=1;
	}
}
void fa(vector<bool> &s, vector<bool> &ans){
	
	queue<int> q;
	for (int i = 0; i < s.size(); i++){
		if (s[i]){
			q.push(i);
			ans[i] = 1;
		}
	}
	while (!q.empty()){
		int v = q.front();
		q.pop();
		for (auto to : ing[v]){
			if (ans[to]) continue;
			bool mb = true;
			for (auto k : g[to]){
				mb &= ans[k] == 1;
			}
			if (col[to] || mb){
				ans[to]=1;
				q.push(to);
			}
		}
	}
}

void fb(vector<bool> &s, vector<bool> &ans){
	queue<int> q;
	for (int i = 0; i < s.size();i++){
		if (s[i]){
			q.push(i);
			ans[i] = 1;
		}
	}
	while (!q.empty()){
		int v = q.front();
		q.pop();
		for (auto to : ing[v]){
			if (ans[to]) continue;
			bool mb = true;
			for (auto k : g[to]){
				mb &= ans[k] == 1;
			}
			if (!col[to] || mb){
				ans[to] = 1;
				q.push(to);
			}
		}
	}
}

void intersect(vector<bool> &a, vector<bool> &b, vector<bool> &ans){
	for (int i = 0; i < a.size();i++){
		if (b[i] && a[i]) ans[i]=1;
	}
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	n = a.size();
	m = u.size();
	for (int i = 0; i < m; i++){
		g[u[i]].push_back(v[i]);
		ing[v[i]].push_back(u[i]);
	}
	for (int i = 0; i < n; i++){
		if (a[i]){
			col[i] = true;
		}
	}
	for (int i = 0; i < n; i++){
		if (r[i]) chrg[i] = true;
	}
	
	while (1){
		vector<bool> R(n);
		for (int i = 0; i < n; i++){
			if (chrg[i]) R[i]=1;
		}
		vector<bool>  far(n), gg(n) , x(n), ht(n);
		fa(R, far);
		rev(far, gg);
		fb(gg, x);
		intersect(far, x, ht);
		bool mb = false;
		for (int i = 0; i < ht.size();i++){
			if (ht[i] && chrg[i]) mb = true, chrg[i] = false;
		}
		if (!mb){
			vector<int> ans(n,1);
			for (int i = 0; i < x.size();i++){
				if (x[i])
					ans[i] = 0;
			}
			return ans;
		}
	}
}
/*
2 4 
0 1 
1 0 
0 0 
0 1 
1 0 
1 1 

*/

Compilation message

train.cpp: In function 'void fa(std::vector<bool>&, std::vector<bool>&)':
train.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.size(); i++){
                  ~~^~~~~~~~~~
train.cpp: In function 'void fb(std::vector<bool>&, std::vector<bool>&)':
train.cpp:49:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.size();i++){
                  ~~^~~~~~~~~~
train.cpp: In function 'void intersect(std::vector<bool>&, std::vector<bool>&, std::vector<bool>&)':
train.cpp:73:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.size();i++){
                  ~~^~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:105:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < ht.size();i++){
                   ~~^~~~~~~~~~~
train.cpp:110:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < x.size();i++){
                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1016 KB Output is correct
2 Correct 9 ms 1124 KB Output is correct
3 Correct 9 ms 1344 KB Output is correct
4 Correct 12 ms 1344 KB Output is correct
5 Correct 7 ms 1344 KB Output is correct
6 Correct 8 ms 1344 KB Output is correct
7 Correct 7 ms 1344 KB Output is correct
8 Correct 8 ms 1344 KB Output is correct
9 Correct 7 ms 1376 KB Output is correct
10 Correct 11 ms 1376 KB Output is correct
11 Correct 7 ms 1376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1376 KB Output is correct
2 Correct 2 ms 1376 KB Output is correct
3 Correct 2 ms 1376 KB Output is correct
4 Correct 2 ms 1376 KB Output is correct
5 Correct 2 ms 1376 KB Output is correct
6 Correct 2 ms 1376 KB Output is correct
7 Correct 2 ms 1376 KB Output is correct
8 Correct 2 ms 1376 KB Output is correct
9 Correct 2 ms 1376 KB Output is correct
10 Correct 2 ms 1376 KB Output is correct
11 Correct 2 ms 1376 KB Output is correct
12 Correct 2 ms 1376 KB Output is correct
13 Correct 2 ms 1376 KB Output is correct
14 Correct 2 ms 1376 KB Output is correct
15 Correct 2 ms 1376 KB Output is correct
16 Correct 2 ms 1376 KB Output is correct
17 Correct 2 ms 1376 KB Output is correct
18 Correct 2 ms 1376 KB Output is correct
19 Correct 2 ms 1376 KB Output is correct
20 Correct 3 ms 1376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 1724 KB Output is correct
2 Correct 309 ms 1776 KB Output is correct
3 Correct 423 ms 1776 KB Output is correct
4 Correct 12 ms 1776 KB Output is correct
5 Correct 14 ms 1776 KB Output is correct
6 Correct 22 ms 1824 KB Output is correct
7 Correct 13 ms 1824 KB Output is correct
8 Correct 11 ms 1824 KB Output is correct
9 Correct 11 ms 1824 KB Output is correct
10 Correct 14 ms 1824 KB Output is correct
11 Correct 12 ms 1824 KB Output is correct
12 Correct 14 ms 1824 KB Output is correct
13 Correct 12 ms 1824 KB Output is correct
14 Correct 16 ms 1824 KB Output is correct
15 Correct 14 ms 1824 KB Output is correct
16 Correct 11 ms 1824 KB Output is correct
17 Correct 12 ms 1824 KB Output is correct
18 Correct 694 ms 1824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1824 KB Output is correct
2 Correct 12 ms 1824 KB Output is correct
3 Correct 13 ms 1824 KB Output is correct
4 Correct 12 ms 1824 KB Output is correct
5 Correct 20 ms 1824 KB Output is correct
6 Correct 19 ms 1824 KB Output is correct
7 Correct 20 ms 1824 KB Output is correct
8 Correct 18 ms 1824 KB Output is correct
9 Correct 11 ms 1824 KB Output is correct
10 Correct 19 ms 1852 KB Output is correct
11 Correct 14 ms 1852 KB Output is correct
12 Correct 11 ms 1852 KB Output is correct
13 Correct 11 ms 1852 KB Output is correct
14 Correct 12 ms 1852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 1852 KB Output is correct
2 Correct 19 ms 1852 KB Output is correct
3 Correct 13 ms 1852 KB Output is correct
4 Correct 17 ms 1852 KB Output is correct
5 Correct 3 ms 1852 KB Output is correct
6 Correct 6 ms 1852 KB Output is correct
7 Correct 8 ms 1852 KB Output is correct
8 Correct 9 ms 1852 KB Output is correct
9 Correct 9 ms 1852 KB Output is correct
10 Correct 3 ms 1852 KB Output is correct
11 Correct 13 ms 1852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1016 KB Output is correct
2 Correct 9 ms 1124 KB Output is correct
3 Correct 9 ms 1344 KB Output is correct
4 Correct 12 ms 1344 KB Output is correct
5 Correct 7 ms 1344 KB Output is correct
6 Correct 8 ms 1344 KB Output is correct
7 Correct 7 ms 1344 KB Output is correct
8 Correct 8 ms 1344 KB Output is correct
9 Correct 7 ms 1376 KB Output is correct
10 Correct 11 ms 1376 KB Output is correct
11 Correct 7 ms 1376 KB Output is correct
12 Correct 2 ms 1376 KB Output is correct
13 Correct 2 ms 1376 KB Output is correct
14 Correct 2 ms 1376 KB Output is correct
15 Correct 2 ms 1376 KB Output is correct
16 Correct 2 ms 1376 KB Output is correct
17 Correct 2 ms 1376 KB Output is correct
18 Correct 2 ms 1376 KB Output is correct
19 Correct 2 ms 1376 KB Output is correct
20 Correct 2 ms 1376 KB Output is correct
21 Correct 2 ms 1376 KB Output is correct
22 Correct 2 ms 1376 KB Output is correct
23 Correct 2 ms 1376 KB Output is correct
24 Correct 2 ms 1376 KB Output is correct
25 Correct 2 ms 1376 KB Output is correct
26 Correct 2 ms 1376 KB Output is correct
27 Correct 2 ms 1376 KB Output is correct
28 Correct 2 ms 1376 KB Output is correct
29 Correct 2 ms 1376 KB Output is correct
30 Correct 2 ms 1376 KB Output is correct
31 Correct 3 ms 1376 KB Output is correct
32 Correct 139 ms 1724 KB Output is correct
33 Correct 309 ms 1776 KB Output is correct
34 Correct 423 ms 1776 KB Output is correct
35 Correct 12 ms 1776 KB Output is correct
36 Correct 14 ms 1776 KB Output is correct
37 Correct 22 ms 1824 KB Output is correct
38 Correct 13 ms 1824 KB Output is correct
39 Correct 11 ms 1824 KB Output is correct
40 Correct 11 ms 1824 KB Output is correct
41 Correct 14 ms 1824 KB Output is correct
42 Correct 12 ms 1824 KB Output is correct
43 Correct 14 ms 1824 KB Output is correct
44 Correct 12 ms 1824 KB Output is correct
45 Correct 16 ms 1824 KB Output is correct
46 Correct 14 ms 1824 KB Output is correct
47 Correct 11 ms 1824 KB Output is correct
48 Correct 12 ms 1824 KB Output is correct
49 Correct 694 ms 1824 KB Output is correct
50 Correct 9 ms 1824 KB Output is correct
51 Correct 12 ms 1824 KB Output is correct
52 Correct 13 ms 1824 KB Output is correct
53 Correct 12 ms 1824 KB Output is correct
54 Correct 20 ms 1824 KB Output is correct
55 Correct 19 ms 1824 KB Output is correct
56 Correct 20 ms 1824 KB Output is correct
57 Correct 18 ms 1824 KB Output is correct
58 Correct 11 ms 1824 KB Output is correct
59 Correct 19 ms 1852 KB Output is correct
60 Correct 14 ms 1852 KB Output is correct
61 Correct 11 ms 1852 KB Output is correct
62 Correct 11 ms 1852 KB Output is correct
63 Correct 12 ms 1852 KB Output is correct
64 Correct 19 ms 1852 KB Output is correct
65 Correct 19 ms 1852 KB Output is correct
66 Correct 13 ms 1852 KB Output is correct
67 Correct 17 ms 1852 KB Output is correct
68 Correct 3 ms 1852 KB Output is correct
69 Correct 6 ms 1852 KB Output is correct
70 Correct 8 ms 1852 KB Output is correct
71 Correct 9 ms 1852 KB Output is correct
72 Correct 9 ms 1852 KB Output is correct
73 Correct 3 ms 1852 KB Output is correct
74 Correct 13 ms 1852 KB Output is correct
75 Execution timed out 2071 ms 1852 KB Time limit exceeded
76 Halted 0 ms 0 KB -