답안 #789619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789619 2023-07-21T14:55:22 Z esomer 장난감 기차 (IOI17_train) C++17
49 / 100
2000 ms 1356 KB
#include<bits/stdc++.h>
#include "train.h"

using namespace std;

typedef long long ll;

//~ vector<int> who_wins2(vector<int> A, vector<int> R, vector<int> U, vector<int> V){
	//~ int n = (int)A.size();
	//~ int m = (int)U.size();
	//~ bool first = 1;
	//~ for(int i = 0; i < m; i++){
		//~ if(V[i] != U[i] && V[i] != U[i] + 1) first = 0;
	//~ }
	//~ if(first){
		//~ vector<bool> self(n, 0);
		//~ vector<bool> other(n, 0);
		//~ for(int i = 0; i < m; i++){
			//~ if(U[i] == V[i]) self[U[i]] = 1;
			//~ else other[U[i]] = 1;
		//~ }
		//~ vector<int> ans(n, 0);
		//~ for(int i = n - 1; i >= 0; i--){
			//~ if(A[i] == 1){
				//~ if(self[i] == 1 && R[i] == 1) ans[i] = 1;
				//~ else if(other[i] == 1) ans[i] = ans[i+1];
			//~ }else{
				//~ if(self[i] == 1){
					//~ if(R[i] == 0) ans[i] = 0;
					//~ else{
						//~ if(other[i]) ans[i] = ans[i+1];
						//~ else ans[i] = 1;
					//~ }
				//~ }else if(other[i] == 1) ans[i] = ans[i+1];
			//~ }
		//~ }
		//~ return ans;
	//~ }else return {};
//~ }

void process(vector<int>& A, vector<int>& R, vector<int>& U, vector<int>& V, vector<bool>& forced){
	int n = (int)A.size();
	int m = (int)U.size();
	vector<vector<int>> radj(n);
	vector<int> out(n, 0);
	for(int i = 0; i < m; i++){
		if(R[U[i]] == 1) continue;
		out[U[i]]++;
		radj[V[i]].push_back(U[i]);
	}
	queue<int> q;
	for(int i = 0; i < n; i++){
		if(out[i] == 0){
			forced[i] = 0;
			q.push(i);
		}
	}
	while(!q.empty()){
		int x = q.front(); q.pop();
		for(int node : radj[x]){
			out[node]--;
			if(out[node] == 0 && forced[node] == 1) {q.push(node); forced[node] = 0;}
			if(A[node] == 1 && forced[node] == 1){
				forced[node] = 0;
				q.push(node);
			}
		}
	}
	radj.assign(n, {});
	out.assign(n, 0);
	for(int i = 0; i < m; i++){
		if(forced[U[i]] == 1) continue;
		out[U[i]]++;
		radj[V[i]].push_back(U[i]);
	}
	for(int i = 0; i < n; i++){
		if(out[i] == 0){
			q.push(i);
		}
	}
	while(!q.empty()){
		int x = q.front(); q.pop();
		for(int node : radj[x]){
			out[node]--;
			if(out[node] == 0 && forced[node] == 0) {q.push(node); forced[node] = 1;}
			if(A[node] == 0 && forced[node] == 0){
				forced[node] = 1;
				q.push(node);
			}
		}
	}
}

vector<int> who_wins(vector<int> A, vector<int> R, vector<int> U, vector<int> V){
	int n = (int)A.size();
	int m = (int)U.size();
	bool stop = 0;
	vector<bool> forced; //If 1, then it can be forced by B into a cycle with no R's.
	while(!stop){
		stop = 1;
		forced.assign(n, 1);
		process(A, R, U, V, forced);
		for(int i = 0; i < n; i++){
			if(forced[i] == 1 && R[i] == 1) {R[i] = 0; stop = 0;}
		}
	}
	vector<int> ans(n);
	for(int i = 0; i < n; i++){
		if(forced[i] == 1) ans[i] = 0;
		else ans[i] = 1;
	}
	return ans;
}

//~ mt19937 gen(time(0));

//~ void generate(){
	//~ for(int tt = 0; tt <= 10000; tt++){
		//~ int n = gen() % 5 + 1;
		//~ int m = gen() % 5 + n;
		//~ vector<int> a(n), r(n), u(m), v(m);

		//~ for(int i = 0; i < n; i++)
			//~ a[i] = gen() % 2;

		//~ for(int i = 0; i < n; i++)
			//~ r[i] = gen() % 2;

		//~ for(int i = 0; i < n; i++){
			//~ u[i] = i;
			//~ if(u[i] == n - 1) v[i] = u[i];
			//~ else v[i] = u[i] + gen() % 2;
		//~ }
		//~ for(int i = n; i < m; i++){
			//~ u[i] = gen() % n;
			//~ if(u[i] == n - 1) v[i] = u[i];
			//~ else v[i] = u[i] + gen() % 2;
		//~ }
		//~ vector<int> res = who_wins(a, r, u, v);
		//~ vector<int> res2 = who_wins2(a, r, u, v);

		//~ if(res != res2){
			//~ cout << n << " " << m << endl;
			//~ for(int x : a) cout << x << " ";
			//~ cout << endl;
			//~ for(int x : r) cout << x << " "; cout << endl;
			//~ for(int i = 0; i < m; i++){
				//~ cout << u[i] << " " << v[i] << endl;
			//~ }
			//~ cout << "RES: ";
			//~ for(int x : res) cout << x << " "; cout << endl;
			//~ cout << "RES2: ";
			//~ for(int x : res2) cout << x << " "; cout << endl;
			//~ return;
		//~ }
	//~ }
//~ }

//~ int main() {
	
	//~ generate(); return 0;

	//~ freopen("in.txt", "r", stdin);

	//~ int n, m;
	//~ assert(2 == scanf("%d %d", &n, &m));
 
	//~ vector<int> a(n), r(n), u(m), v(m);
 
	//~ for(int i = 0; i < n; i++)
		//~ assert(1 == scanf("%d", &a[i]));
 
	//~ for(int i = 0; i < n; i++)
		//~ assert(1 == scanf("%d", &r[i]));
 
	//~ for(int i = 0; i < m; i++)
		//~ assert(2 == scanf("%d %d", &u[i], &v[i]));
 
	//~ vector<int> res = who_wins(a, r, u, v);
 
	//~ for(int i = 0; i < (int)res.size(); i++)
		//~ printf(i ? " %d" : "%d", res[i]);
	//~ printf("\n");

	//~ return 0;
//~ }

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:96:6: warning: unused variable 'm' [-Wunused-variable]
   96 |  int m = (int)U.size();
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 852 KB Output is correct
2 Correct 7 ms 852 KB Output is correct
3 Correct 6 ms 820 KB Output is correct
4 Correct 6 ms 856 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 7 ms 852 KB Output is correct
7 Correct 4 ms 852 KB Output is correct
8 Correct 5 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 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 304 KB Output is correct
16 Correct 0 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 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 274 ms 1272 KB Output is correct
2 Correct 557 ms 1356 KB Output is correct
3 Correct 822 ms 1264 KB Output is correct
4 Correct 7 ms 1236 KB Output is correct
5 Correct 8 ms 1204 KB Output is correct
6 Correct 10 ms 1252 KB Output is correct
7 Correct 6 ms 1212 KB Output is correct
8 Correct 5 ms 1236 KB Output is correct
9 Correct 5 ms 1180 KB Output is correct
10 Correct 6 ms 1108 KB Output is correct
11 Correct 5 ms 1108 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 6 ms 1236 KB Output is correct
14 Correct 6 ms 1236 KB Output is correct
15 Correct 6 ms 1236 KB Output is correct
16 Correct 6 ms 1208 KB Output is correct
17 Correct 6 ms 1212 KB Output is correct
18 Correct 1383 ms 940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 980 KB Output is correct
2 Correct 6 ms 1096 KB Output is correct
3 Correct 6 ms 1236 KB Output is correct
4 Correct 7 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 1192 KB Output is correct
8 Correct 6 ms 1184 KB Output is correct
9 Correct 6 ms 1080 KB Output is correct
10 Correct 6 ms 1236 KB Output is correct
11 Correct 5 ms 1212 KB Output is correct
12 Correct 5 ms 1208 KB Output is correct
13 Correct 6 ms 1236 KB Output is correct
14 Correct 5 ms 1080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1236 KB Output is correct
2 Correct 6 ms 1244 KB Output is correct
3 Correct 6 ms 1236 KB Output is correct
4 Correct 7 ms 1176 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 4 ms 824 KB Output is correct
8 Correct 4 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 852 KB Output is correct
2 Correct 7 ms 852 KB Output is correct
3 Correct 6 ms 820 KB Output is correct
4 Correct 6 ms 856 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 7 ms 852 KB Output is correct
7 Correct 4 ms 852 KB Output is correct
8 Correct 5 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 3 ms 724 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 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 296 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 300 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 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 304 KB Output is correct
27 Correct 0 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 296 KB Output is correct
32 Correct 274 ms 1272 KB Output is correct
33 Correct 557 ms 1356 KB Output is correct
34 Correct 822 ms 1264 KB Output is correct
35 Correct 7 ms 1236 KB Output is correct
36 Correct 8 ms 1204 KB Output is correct
37 Correct 10 ms 1252 KB Output is correct
38 Correct 6 ms 1212 KB Output is correct
39 Correct 5 ms 1236 KB Output is correct
40 Correct 5 ms 1180 KB Output is correct
41 Correct 6 ms 1108 KB Output is correct
42 Correct 5 ms 1108 KB Output is correct
43 Correct 7 ms 1212 KB Output is correct
44 Correct 6 ms 1236 KB Output is correct
45 Correct 6 ms 1236 KB Output is correct
46 Correct 6 ms 1236 KB Output is correct
47 Correct 6 ms 1208 KB Output is correct
48 Correct 6 ms 1212 KB Output is correct
49 Correct 1383 ms 940 KB Output is correct
50 Correct 5 ms 980 KB Output is correct
51 Correct 6 ms 1096 KB Output is correct
52 Correct 6 ms 1236 KB Output is correct
53 Correct 7 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 1192 KB Output is correct
57 Correct 6 ms 1184 KB Output is correct
58 Correct 6 ms 1080 KB Output is correct
59 Correct 6 ms 1236 KB Output is correct
60 Correct 5 ms 1212 KB Output is correct
61 Correct 5 ms 1208 KB Output is correct
62 Correct 6 ms 1236 KB Output is correct
63 Correct 5 ms 1080 KB Output is correct
64 Correct 6 ms 1236 KB Output is correct
65 Correct 6 ms 1244 KB Output is correct
66 Correct 6 ms 1236 KB Output is correct
67 Correct 7 ms 1176 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 3 ms 724 KB Output is correct
70 Correct 4 ms 824 KB Output is correct
71 Correct 4 ms 852 KB Output is correct
72 Correct 4 ms 852 KB Output is correct
73 Correct 1 ms 436 KB Output is correct
74 Correct 4 ms 724 KB Output is correct
75 Correct 466 ms 1240 KB Output is correct
76 Correct 552 ms 1268 KB Output is correct
77 Correct 821 ms 1272 KB Output is correct
78 Correct 823 ms 1252 KB Output is correct
79 Correct 815 ms 1264 KB Output is correct
80 Correct 7 ms 1236 KB Output is correct
81 Correct 7 ms 1212 KB Output is correct
82 Correct 8 ms 1336 KB Output is correct
83 Correct 8 ms 1236 KB Output is correct
84 Correct 9 ms 1212 KB Output is correct
85 Correct 8 ms 1236 KB Output is correct
86 Correct 10 ms 1248 KB Output is correct
87 Correct 7 ms 1204 KB Output is correct
88 Correct 16 ms 1256 KB Output is correct
89 Correct 9 ms 1236 KB Output is correct
90 Correct 26 ms 1236 KB Output is correct
91 Correct 26 ms 1236 KB Output is correct
92 Correct 62 ms 1236 KB Output is correct
93 Correct 56 ms 1228 KB Output is correct
94 Correct 59 ms 1236 KB Output is correct
95 Correct 60 ms 1236 KB Output is correct
96 Correct 212 ms 1144 KB Output is correct
97 Correct 1453 ms 1236 KB Output is correct
98 Execution timed out 2047 ms 1216 KB Time limit exceeded
99 Halted 0 ms 0 KB -