답안 #409514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409514 2021-05-21T02:50:49 Z rqi 장난감 기차 (IOI17_train) C++14
100 / 100
994 ms 1888 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pi;

const int MOD = 1e9+7;

#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define bk back()

#define all(x) begin(x), end(x)

const int mx = 5005;
int n, m;
vi a, r, u, v;
vi adj[mx];
vi radj[mx];
bool bad[mx];

int getBType(){

	for(int i = 0; i < n; i++){
		if(bad[i]) continue;
		if(a[i] == 1){
			bool works = 1;
			for(auto u: adj[i]){
				if(!bad[u]){
					works = 0;
					break;
				}
			}
			if(works){
				return i;
			}
		}
		else{
			for(auto u: adj[i]){
				if(bad[u]){
					return i;
				}
			}
		}
	}
	//cout << "getB Over" << "\n";
	return -1;
}

array<bool, mx> dp;
array<bool, mx> ndp;
bool forced[mx];
int cur_deg[mx]; //number of neighbors that can be forced into a good C
int bad_cur_deg[mx];
int self[mx];
 
queue<int> to_unForce;
 
void iForce(int node){
	//cout << "iForce: " << node << "\n";
	for(auto u: radj[node]){
		if(forced[u] || bad[u]) continue;
		if(a[u] == 0){
			cur_deg[u]++;
			//cout << u << " " << cur_deg[u] << "\n";
			if(cur_deg[u] == sz(adj[u])){
				forced[u] = 1;
				to_unForce.push(u);
			}
		}
		else{
			forced[u] = 1;
			to_unForce.push(u);
		}
	}
}
 
void initForce(){
	for(int i = 0; i < n; i++){
		forced[i] = 0;
		cur_deg[i] = 0;
	}
	for(int i = 0; i < n; i++){
		if(bad[i]) continue;
		if(r[i] == 1){
			if(!forced[i]){
				forced[i] = 1;
				to_unForce.push(i);
			}
		}
	}
 
	while(sz(to_unForce)){
		int node = to_unForce.front();
		to_unForce.pop();
		iForce(node);
	}
}

int getAType(){
	
	initForce();
	for(int i = 0; i < n; i++){
		if(!bad[i] && !forced[i] && a[i] == 1){
			return i;
		}
	}

	//cout << "getA over" << "\n";
	return -1;
}

vi who_wins(vi _a, vi _r, vi _u, vi _v) {
	a = _a;
	r = _r;
	u = _u;
	v = _v;
	n = sz(a);
	m = sz(u);
	for(int i = 0; i < m; i++){
		adj[u[i]].pb(v[i]);
		radj[v[i]].pb(u[i]);
	}
	for(int i = 0; i < n; i++){
		for(auto u: adj[i]){
			if(u == i) self[i]++;
		}
	}

	for(int i = 0; i < n; i++){
		dp[i] = 1;
		if(r[i] == 1) dp[i] = 0;
	}
	for(int rep = 0; rep < mx; rep++){
		for(int i = 0; i < n; i++){
			ndp[i] = 0;
		}
		for(int i = 0; i < n; i++){
			if(r[i] == 1) continue;
			if(a[i] == 1){
				ndp[i] = 1;
				for(auto u: adj[i]){
					if(dp[u] == 0) ndp[i] = 0;
				}
			}
			else{
				ndp[i] = 0;
				for(auto u: adj[i]){
					if(dp[u] == 1) ndp[i] = 1;
				}
			}
		}
		swap(dp, ndp);
	}

	for(int i = 0; i < n; i++){
		if(dp[i] == 1){
			bad[i] = 1;
			//cout << "initial bad: " << i << "\n";
		}
	}

	while(true){
		int node = getBType();
		if(node == -1){
			node = getAType();
		}
		if(node == -1) break;
		//cout << "node: " << node << "\n";
		bad[node] = 1;
	}

	vi ans(n, 0);
	for(int i = 0; i < n; i++){
		if(!bad[i]){
			ans[i] = 1;
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 1228 KB Output is correct
2 Correct 249 ms 1376 KB Output is correct
3 Correct 247 ms 1228 KB Output is correct
4 Correct 249 ms 1228 KB Output is correct
5 Correct 255 ms 1228 KB Output is correct
6 Correct 246 ms 1220 KB Output is correct
7 Correct 222 ms 1220 KB Output is correct
8 Correct 206 ms 1260 KB Output is correct
9 Correct 236 ms 1192 KB Output is correct
10 Correct 216 ms 1180 KB Output is correct
11 Correct 177 ms 1220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 540 KB Output is correct
2 Correct 43 ms 552 KB Output is correct
3 Correct 45 ms 460 KB Output is correct
4 Correct 45 ms 460 KB Output is correct
5 Correct 41 ms 532 KB Output is correct
6 Correct 41 ms 532 KB Output is correct
7 Correct 43 ms 552 KB Output is correct
8 Correct 41 ms 544 KB Output is correct
9 Correct 42 ms 540 KB Output is correct
10 Correct 41 ms 536 KB Output is correct
11 Correct 42 ms 548 KB Output is correct
12 Correct 41 ms 540 KB Output is correct
13 Correct 41 ms 460 KB Output is correct
14 Correct 41 ms 548 KB Output is correct
15 Correct 41 ms 544 KB Output is correct
16 Correct 41 ms 548 KB Output is correct
17 Correct 41 ms 652 KB Output is correct
18 Correct 41 ms 536 KB Output is correct
19 Correct 42 ms 548 KB Output is correct
20 Correct 42 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 476 ms 1832 KB Output is correct
2 Correct 514 ms 1788 KB Output is correct
3 Correct 498 ms 1860 KB Output is correct
4 Correct 443 ms 1764 KB Output is correct
5 Correct 656 ms 1788 KB Output is correct
6 Correct 994 ms 1760 KB Output is correct
7 Correct 290 ms 1740 KB Output is correct
8 Correct 817 ms 1752 KB Output is correct
9 Correct 408 ms 1692 KB Output is correct
10 Correct 744 ms 1708 KB Output is correct
11 Correct 816 ms 1732 KB Output is correct
12 Correct 444 ms 1640 KB Output is correct
13 Correct 364 ms 1760 KB Output is correct
14 Correct 364 ms 1760 KB Output is correct
15 Correct 368 ms 1756 KB Output is correct
16 Correct 359 ms 1764 KB Output is correct
17 Correct 364 ms 1772 KB Output is correct
18 Correct 543 ms 1460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 1504 KB Output is correct
2 Correct 520 ms 1588 KB Output is correct
3 Correct 782 ms 1740 KB Output is correct
4 Correct 539 ms 1860 KB Output is correct
5 Correct 711 ms 1740 KB Output is correct
6 Correct 578 ms 1720 KB Output is correct
7 Correct 586 ms 1720 KB Output is correct
8 Correct 636 ms 1692 KB Output is correct
9 Correct 148 ms 1632 KB Output is correct
10 Correct 212 ms 1772 KB Output is correct
11 Correct 137 ms 1748 KB Output is correct
12 Correct 230 ms 1760 KB Output is correct
13 Correct 802 ms 1756 KB Output is correct
14 Correct 579 ms 1636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 879 ms 1812 KB Output is correct
2 Correct 393 ms 1816 KB Output is correct
3 Correct 697 ms 1760 KB Output is correct
4 Correct 414 ms 1640 KB Output is correct
5 Correct 64 ms 640 KB Output is correct
6 Correct 217 ms 1152 KB Output is correct
7 Correct 404 ms 1380 KB Output is correct
8 Correct 573 ms 1356 KB Output is correct
9 Correct 521 ms 1416 KB Output is correct
10 Correct 136 ms 784 KB Output is correct
11 Correct 355 ms 1332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 1228 KB Output is correct
2 Correct 249 ms 1376 KB Output is correct
3 Correct 247 ms 1228 KB Output is correct
4 Correct 249 ms 1228 KB Output is correct
5 Correct 255 ms 1228 KB Output is correct
6 Correct 246 ms 1220 KB Output is correct
7 Correct 222 ms 1220 KB Output is correct
8 Correct 206 ms 1260 KB Output is correct
9 Correct 236 ms 1192 KB Output is correct
10 Correct 216 ms 1180 KB Output is correct
11 Correct 177 ms 1220 KB Output is correct
12 Correct 42 ms 540 KB Output is correct
13 Correct 43 ms 552 KB Output is correct
14 Correct 45 ms 460 KB Output is correct
15 Correct 45 ms 460 KB Output is correct
16 Correct 41 ms 532 KB Output is correct
17 Correct 41 ms 532 KB Output is correct
18 Correct 43 ms 552 KB Output is correct
19 Correct 41 ms 544 KB Output is correct
20 Correct 42 ms 540 KB Output is correct
21 Correct 41 ms 536 KB Output is correct
22 Correct 42 ms 548 KB Output is correct
23 Correct 41 ms 540 KB Output is correct
24 Correct 41 ms 460 KB Output is correct
25 Correct 41 ms 548 KB Output is correct
26 Correct 41 ms 544 KB Output is correct
27 Correct 41 ms 548 KB Output is correct
28 Correct 41 ms 652 KB Output is correct
29 Correct 41 ms 536 KB Output is correct
30 Correct 42 ms 548 KB Output is correct
31 Correct 42 ms 544 KB Output is correct
32 Correct 476 ms 1832 KB Output is correct
33 Correct 514 ms 1788 KB Output is correct
34 Correct 498 ms 1860 KB Output is correct
35 Correct 443 ms 1764 KB Output is correct
36 Correct 656 ms 1788 KB Output is correct
37 Correct 994 ms 1760 KB Output is correct
38 Correct 290 ms 1740 KB Output is correct
39 Correct 817 ms 1752 KB Output is correct
40 Correct 408 ms 1692 KB Output is correct
41 Correct 744 ms 1708 KB Output is correct
42 Correct 816 ms 1732 KB Output is correct
43 Correct 444 ms 1640 KB Output is correct
44 Correct 364 ms 1760 KB Output is correct
45 Correct 364 ms 1760 KB Output is correct
46 Correct 368 ms 1756 KB Output is correct
47 Correct 359 ms 1764 KB Output is correct
48 Correct 364 ms 1772 KB Output is correct
49 Correct 543 ms 1460 KB Output is correct
50 Correct 115 ms 1504 KB Output is correct
51 Correct 520 ms 1588 KB Output is correct
52 Correct 782 ms 1740 KB Output is correct
53 Correct 539 ms 1860 KB Output is correct
54 Correct 711 ms 1740 KB Output is correct
55 Correct 578 ms 1720 KB Output is correct
56 Correct 586 ms 1720 KB Output is correct
57 Correct 636 ms 1692 KB Output is correct
58 Correct 148 ms 1632 KB Output is correct
59 Correct 212 ms 1772 KB Output is correct
60 Correct 137 ms 1748 KB Output is correct
61 Correct 230 ms 1760 KB Output is correct
62 Correct 802 ms 1756 KB Output is correct
63 Correct 579 ms 1636 KB Output is correct
64 Correct 879 ms 1812 KB Output is correct
65 Correct 393 ms 1816 KB Output is correct
66 Correct 697 ms 1760 KB Output is correct
67 Correct 414 ms 1640 KB Output is correct
68 Correct 64 ms 640 KB Output is correct
69 Correct 217 ms 1152 KB Output is correct
70 Correct 404 ms 1380 KB Output is correct
71 Correct 573 ms 1356 KB Output is correct
72 Correct 521 ms 1416 KB Output is correct
73 Correct 136 ms 784 KB Output is correct
74 Correct 355 ms 1332 KB Output is correct
75 Correct 437 ms 1752 KB Output is correct
76 Correct 635 ms 1784 KB Output is correct
77 Correct 693 ms 1808 KB Output is correct
78 Correct 681 ms 1816 KB Output is correct
79 Correct 719 ms 1780 KB Output is correct
80 Correct 485 ms 1760 KB Output is correct
81 Correct 799 ms 1748 KB Output is correct
82 Correct 732 ms 1760 KB Output is correct
83 Correct 680 ms 1860 KB Output is correct
84 Correct 698 ms 1772 KB Output is correct
85 Correct 607 ms 1748 KB Output is correct
86 Correct 743 ms 1768 KB Output is correct
87 Correct 821 ms 1748 KB Output is correct
88 Correct 709 ms 1740 KB Output is correct
89 Correct 747 ms 1860 KB Output is correct
90 Correct 709 ms 1764 KB Output is correct
91 Correct 686 ms 1764 KB Output is correct
92 Correct 698 ms 1768 KB Output is correct
93 Correct 558 ms 1784 KB Output is correct
94 Correct 711 ms 1816 KB Output is correct
95 Correct 762 ms 1888 KB Output is correct
96 Correct 522 ms 1688 KB Output is correct
97 Correct 841 ms 1740 KB Output is correct
98 Correct 854 ms 1868 KB Output is correct
99 Correct 749 ms 1732 KB Output is correct
100 Correct 535 ms 1348 KB Output is correct