답안 #725626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725626 2023-04-17T19:06:27 Z WonderfulWhale Stranded Far From Home (BOI22_island) C++17
100 / 100
976 ms 141420 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define st first
#define nd second
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

const int MAXN = 200009;

int tab[MAXN];
vector<int> G[MAXN];
bool ans[MAXN];
map<int, vector<int>> M;
map<int, vector<pii>> edges;
int dependency[MAXN];

int p[MAXN];
int sum[MAXN];
multiset<pii> S[MAXN];
vector<int> cost;

int Find(int x) {
	return p[x]==x?x:p[x]=Find(p[x]);
}

void Union(int x, int y) {
	int X = Find(x);
	int Y = Find(y);
	if(X==Y) return;
	if(sz(S[X])<sz(S[Y])) swap(X, Y);
	p[Y] = X;
	sum[X] += sum[Y];
	sum[X] = min(sum[X], 1000000009);
	for(pii val:S[Y]) {
		S[X].insert(val);
	}
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m;
	cin >> n >> m;
	int Max = 0;
	for(int i=1;i<=n;i++) {
		cin >> tab[i];
		M[tab[i]].pb(i);
		Max = max(Max, tab[i]);
	}
	for(int i=0;i<m;i++) {
		int a, b;
		cin >> a >> b;
		G[a].pb(b);
		G[b].pb(a);
		edges[max(tab[a], tab[b])].pb({a, b});
	}
	for(int i=1;i<=n;i++) {
		p[i] = i;
		sum[i] = tab[i];
		for(int x:G[i]) {
			if(tab[x]>tab[i]) {
				S[i].insert({tab[x], x});
			}
		}
	}
	for(auto &x:M) {
		for(pii y:edges[x.st]) {
			Union(y.st, y.nd);
		}
		for(int y:x.nd) {
			int Y = Find(y);
			auto it = S[Y].upper_bound({sum[Y], 1e9});
			if(it!=S[Y].begin()) {
				it--;
				dependency[y] = it->nd;
			}
		}
	}
	for(int x:M[Max]) {
		ans[x] = true;
	}
	M.erase(Max);
	for(auto it = M.rbegin();it!=M.rend();it++) {
		for(int y:(*it).nd) {
			if(ans[dependency[y]]) {
				ans[y] = true;
			}
		}
	}
	for(int i=1;i<=n;i++) {
		cout << ans[i];
	}
	cout << "\n";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14428 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 11 ms 15192 KB Output is correct
5 Correct 13 ms 15212 KB Output is correct
6 Correct 10 ms 14572 KB Output is correct
7 Correct 12 ms 15060 KB Output is correct
8 Correct 11 ms 15060 KB Output is correct
9 Correct 12 ms 14592 KB Output is correct
10 Correct 26 ms 15240 KB Output is correct
11 Correct 12 ms 15336 KB Output is correct
12 Correct 11 ms 15444 KB Output is correct
13 Correct 9 ms 14500 KB Output is correct
14 Correct 13 ms 14796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 10 ms 14420 KB Output is correct
3 Correct 540 ms 90320 KB Output is correct
4 Correct 212 ms 26068 KB Output is correct
5 Correct 746 ms 113620 KB Output is correct
6 Correct 735 ms 108844 KB Output is correct
7 Correct 866 ms 118176 KB Output is correct
8 Correct 159 ms 26976 KB Output is correct
9 Correct 756 ms 141344 KB Output is correct
10 Correct 300 ms 73212 KB Output is correct
11 Correct 133 ms 27888 KB Output is correct
12 Correct 177 ms 30352 KB Output is correct
13 Correct 135 ms 25728 KB Output is correct
14 Correct 161 ms 26024 KB Output is correct
15 Correct 544 ms 87020 KB Output is correct
16 Correct 306 ms 86308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14432 KB Output is correct
2 Correct 966 ms 130592 KB Output is correct
3 Correct 867 ms 121028 KB Output is correct
4 Correct 200 ms 26536 KB Output is correct
5 Correct 159 ms 26016 KB Output is correct
6 Correct 939 ms 129892 KB Output is correct
7 Correct 534 ms 87360 KB Output is correct
8 Correct 532 ms 87300 KB Output is correct
9 Correct 361 ms 86560 KB Output is correct
10 Correct 482 ms 109084 KB Output is correct
11 Correct 449 ms 79744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14332 KB Output is correct
2 Correct 506 ms 60268 KB Output is correct
3 Correct 468 ms 64388 KB Output is correct
4 Correct 597 ms 71848 KB Output is correct
5 Correct 183 ms 26572 KB Output is correct
6 Correct 163 ms 25316 KB Output is correct
7 Correct 145 ms 27452 KB Output is correct
8 Correct 121 ms 35504 KB Output is correct
9 Correct 256 ms 47720 KB Output is correct
10 Correct 143 ms 25688 KB Output is correct
11 Correct 378 ms 78060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14428 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 11 ms 15192 KB Output is correct
5 Correct 13 ms 15212 KB Output is correct
6 Correct 10 ms 14572 KB Output is correct
7 Correct 12 ms 15060 KB Output is correct
8 Correct 11 ms 15060 KB Output is correct
9 Correct 12 ms 14592 KB Output is correct
10 Correct 26 ms 15240 KB Output is correct
11 Correct 12 ms 15336 KB Output is correct
12 Correct 11 ms 15444 KB Output is correct
13 Correct 9 ms 14500 KB Output is correct
14 Correct 13 ms 14796 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 10 ms 14420 KB Output is correct
17 Correct 540 ms 90320 KB Output is correct
18 Correct 212 ms 26068 KB Output is correct
19 Correct 746 ms 113620 KB Output is correct
20 Correct 735 ms 108844 KB Output is correct
21 Correct 866 ms 118176 KB Output is correct
22 Correct 159 ms 26976 KB Output is correct
23 Correct 756 ms 141344 KB Output is correct
24 Correct 300 ms 73212 KB Output is correct
25 Correct 133 ms 27888 KB Output is correct
26 Correct 177 ms 30352 KB Output is correct
27 Correct 135 ms 25728 KB Output is correct
28 Correct 161 ms 26024 KB Output is correct
29 Correct 544 ms 87020 KB Output is correct
30 Correct 306 ms 86308 KB Output is correct
31 Correct 9 ms 14432 KB Output is correct
32 Correct 966 ms 130592 KB Output is correct
33 Correct 867 ms 121028 KB Output is correct
34 Correct 200 ms 26536 KB Output is correct
35 Correct 159 ms 26016 KB Output is correct
36 Correct 939 ms 129892 KB Output is correct
37 Correct 534 ms 87360 KB Output is correct
38 Correct 532 ms 87300 KB Output is correct
39 Correct 361 ms 86560 KB Output is correct
40 Correct 482 ms 109084 KB Output is correct
41 Correct 449 ms 79744 KB Output is correct
42 Correct 9 ms 14332 KB Output is correct
43 Correct 506 ms 60268 KB Output is correct
44 Correct 468 ms 64388 KB Output is correct
45 Correct 597 ms 71848 KB Output is correct
46 Correct 183 ms 26572 KB Output is correct
47 Correct 163 ms 25316 KB Output is correct
48 Correct 145 ms 27452 KB Output is correct
49 Correct 121 ms 35504 KB Output is correct
50 Correct 256 ms 47720 KB Output is correct
51 Correct 143 ms 25688 KB Output is correct
52 Correct 378 ms 78060 KB Output is correct
53 Correct 8 ms 14420 KB Output is correct
54 Correct 8 ms 14420 KB Output is correct
55 Correct 9 ms 14364 KB Output is correct
56 Correct 11 ms 15084 KB Output is correct
57 Correct 11 ms 15208 KB Output is correct
58 Correct 9 ms 14492 KB Output is correct
59 Correct 11 ms 15060 KB Output is correct
60 Correct 10 ms 15044 KB Output is correct
61 Correct 9 ms 14676 KB Output is correct
62 Correct 12 ms 15316 KB Output is correct
63 Correct 11 ms 15340 KB Output is correct
64 Correct 13 ms 15332 KB Output is correct
65 Correct 9 ms 14548 KB Output is correct
66 Correct 10 ms 14764 KB Output is correct
67 Correct 562 ms 90468 KB Output is correct
68 Correct 158 ms 26208 KB Output is correct
69 Correct 752 ms 113988 KB Output is correct
70 Correct 634 ms 109032 KB Output is correct
71 Correct 706 ms 118416 KB Output is correct
72 Correct 151 ms 27072 KB Output is correct
73 Correct 626 ms 141420 KB Output is correct
74 Correct 266 ms 73356 KB Output is correct
75 Correct 128 ms 27936 KB Output is correct
76 Correct 158 ms 30464 KB Output is correct
77 Correct 146 ms 25844 KB Output is correct
78 Correct 133 ms 26004 KB Output is correct
79 Correct 501 ms 87140 KB Output is correct
80 Correct 297 ms 86428 KB Output is correct
81 Correct 871 ms 130644 KB Output is correct
82 Correct 788 ms 125224 KB Output is correct
83 Correct 172 ms 30696 KB Output is correct
84 Correct 134 ms 28496 KB Output is correct
85 Correct 971 ms 133864 KB Output is correct
86 Correct 567 ms 91208 KB Output is correct
87 Correct 507 ms 91164 KB Output is correct
88 Correct 466 ms 112360 KB Output is correct
89 Correct 421 ms 82212 KB Output is correct
90 Correct 445 ms 64256 KB Output is correct
91 Correct 434 ms 68548 KB Output is correct
92 Correct 445 ms 76152 KB Output is correct
93 Correct 210 ms 30848 KB Output is correct
94 Correct 161 ms 29336 KB Output is correct
95 Correct 129 ms 31724 KB Output is correct
96 Correct 121 ms 38696 KB Output is correct
97 Correct 263 ms 50252 KB Output is correct
98 Correct 149 ms 28556 KB Output is correct
99 Correct 413 ms 81008 KB Output is correct
100 Correct 190 ms 40340 KB Output is correct
101 Correct 976 ms 107688 KB Output is correct
102 Correct 200 ms 28160 KB Output is correct
103 Correct 699 ms 82288 KB Output is correct
104 Correct 820 ms 103696 KB Output is correct