답안 #710909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710909 2023-03-16T04:47:26 Z penguin133 Stranded Far From Home (BOI22_island) C++17
100 / 100
296 ms 48448 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, m, A[300005], par[300005], sz[300005];
vector <int> stuf[300005], adj[300005];
pi B[300005];
bool ans[300005];

int getr(int x){
	return (par[x] == x ? x : par[x] = getr(par[x]));
}

void merge(int a, int b){
	a = getr(a), b = getr(b);
	if(a == b)return;
	if(stuf[a].size() < stuf[b].size())swap(a, b);
	par[b] = a;
	sz[a] += sz[b];
	for(auto i : stuf[b])stuf[a].push_back(i);
}

void solve(){
	cin >> n >> m;
	for(int i=1;i<=n;i++)cin >> A[i];
	while(m--){
		int a, b; cin >> a >> b;
		adj[a].push_back(b); adj[b].push_back(a);
	}
	for(int i=1;i<=n;i++)par[i] = i, B[i] = {A[i], i};
	sort(B+1, B+n+1);
	for(int i=1;i<=n;i++){
		sz[B[i].se] = B[i].fi;
		stuf[B[i].se].push_back(B[i].se);
		for(auto j : adj[B[i].se]){
			if(sz[getr(j)]){
				int x = getr(j);
				if(sz[x] < B[i].fi){
					stuf[x].clear();
				}
				merge(x, B[i].se);
			}
		}
	}
	set <int> s;
	for(int i=1;i<=n;i++){
		if(s.find(getr(i)) != s.end())continue;
		s.insert(getr(i));
		for(auto j : stuf[getr(i)])ans[j] = 1;
	}
	for(int i=1;i<=n;i++)cout << ans[i];
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

island.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 9 ms 14420 KB Output is correct
4 Correct 11 ms 14664 KB Output is correct
5 Correct 10 ms 14664 KB Output is correct
6 Correct 8 ms 14548 KB Output is correct
7 Correct 8 ms 14540 KB Output is correct
8 Correct 9 ms 14548 KB Output is correct
9 Correct 8 ms 14676 KB Output is correct
10 Correct 9 ms 14676 KB Output is correct
11 Correct 9 ms 14676 KB Output is correct
12 Correct 8 ms 14676 KB Output is correct
13 Correct 8 ms 14676 KB Output is correct
14 Correct 10 ms 14676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14476 KB Output is correct
2 Correct 8 ms 14344 KB Output is correct
3 Correct 165 ms 37556 KB Output is correct
4 Correct 159 ms 40412 KB Output is correct
5 Correct 184 ms 44076 KB Output is correct
6 Correct 240 ms 45264 KB Output is correct
7 Correct 197 ms 45192 KB Output is correct
8 Correct 211 ms 42084 KB Output is correct
9 Correct 237 ms 48384 KB Output is correct
10 Correct 127 ms 40024 KB Output is correct
11 Correct 137 ms 41724 KB Output is correct
12 Correct 212 ms 40748 KB Output is correct
13 Correct 133 ms 39372 KB Output is correct
14 Correct 148 ms 39608 KB Output is correct
15 Correct 152 ms 41068 KB Output is correct
16 Correct 95 ms 40244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 233 ms 41464 KB Output is correct
3 Correct 273 ms 46176 KB Output is correct
4 Correct 161 ms 41200 KB Output is correct
5 Correct 149 ms 39524 KB Output is correct
6 Correct 253 ms 45908 KB Output is correct
7 Correct 166 ms 41148 KB Output is correct
8 Correct 152 ms 41136 KB Output is correct
9 Correct 98 ms 40136 KB Output is correct
10 Correct 161 ms 39700 KB Output is correct
11 Correct 187 ms 40008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 269 ms 38704 KB Output is correct
3 Correct 296 ms 43828 KB Output is correct
4 Correct 245 ms 45812 KB Output is correct
5 Correct 276 ms 47280 KB Output is correct
6 Correct 233 ms 43472 KB Output is correct
7 Correct 144 ms 42676 KB Output is correct
8 Correct 96 ms 41408 KB Output is correct
9 Correct 115 ms 31172 KB Output is correct
10 Correct 239 ms 47228 KB Output is correct
11 Correct 183 ms 39808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 9 ms 14420 KB Output is correct
4 Correct 11 ms 14664 KB Output is correct
5 Correct 10 ms 14664 KB Output is correct
6 Correct 8 ms 14548 KB Output is correct
7 Correct 8 ms 14540 KB Output is correct
8 Correct 9 ms 14548 KB Output is correct
9 Correct 8 ms 14676 KB Output is correct
10 Correct 9 ms 14676 KB Output is correct
11 Correct 9 ms 14676 KB Output is correct
12 Correct 8 ms 14676 KB Output is correct
13 Correct 8 ms 14676 KB Output is correct
14 Correct 10 ms 14676 KB Output is correct
15 Correct 8 ms 14476 KB Output is correct
16 Correct 8 ms 14344 KB Output is correct
17 Correct 165 ms 37556 KB Output is correct
18 Correct 159 ms 40412 KB Output is correct
19 Correct 184 ms 44076 KB Output is correct
20 Correct 240 ms 45264 KB Output is correct
21 Correct 197 ms 45192 KB Output is correct
22 Correct 211 ms 42084 KB Output is correct
23 Correct 237 ms 48384 KB Output is correct
24 Correct 127 ms 40024 KB Output is correct
25 Correct 137 ms 41724 KB Output is correct
26 Correct 212 ms 40748 KB Output is correct
27 Correct 133 ms 39372 KB Output is correct
28 Correct 148 ms 39608 KB Output is correct
29 Correct 152 ms 41068 KB Output is correct
30 Correct 95 ms 40244 KB Output is correct
31 Correct 7 ms 14420 KB Output is correct
32 Correct 233 ms 41464 KB Output is correct
33 Correct 273 ms 46176 KB Output is correct
34 Correct 161 ms 41200 KB Output is correct
35 Correct 149 ms 39524 KB Output is correct
36 Correct 253 ms 45908 KB Output is correct
37 Correct 166 ms 41148 KB Output is correct
38 Correct 152 ms 41136 KB Output is correct
39 Correct 98 ms 40136 KB Output is correct
40 Correct 161 ms 39700 KB Output is correct
41 Correct 187 ms 40008 KB Output is correct
42 Correct 7 ms 14420 KB Output is correct
43 Correct 269 ms 38704 KB Output is correct
44 Correct 296 ms 43828 KB Output is correct
45 Correct 245 ms 45812 KB Output is correct
46 Correct 276 ms 47280 KB Output is correct
47 Correct 233 ms 43472 KB Output is correct
48 Correct 144 ms 42676 KB Output is correct
49 Correct 96 ms 41408 KB Output is correct
50 Correct 115 ms 31172 KB Output is correct
51 Correct 239 ms 47228 KB Output is correct
52 Correct 183 ms 39808 KB Output is correct
53 Correct 7 ms 14424 KB Output is correct
54 Correct 7 ms 14440 KB Output is correct
55 Correct 7 ms 14428 KB Output is correct
56 Correct 10 ms 14676 KB Output is correct
57 Correct 10 ms 14740 KB Output is correct
58 Correct 12 ms 14676 KB Output is correct
59 Correct 11 ms 14676 KB Output is correct
60 Correct 10 ms 14572 KB Output is correct
61 Correct 10 ms 14676 KB Output is correct
62 Correct 12 ms 14676 KB Output is correct
63 Correct 10 ms 14676 KB Output is correct
64 Correct 9 ms 14804 KB Output is correct
65 Correct 9 ms 14692 KB Output is correct
66 Correct 9 ms 14676 KB Output is correct
67 Correct 168 ms 42120 KB Output is correct
68 Correct 205 ms 40420 KB Output is correct
69 Correct 201 ms 44124 KB Output is correct
70 Correct 210 ms 45152 KB Output is correct
71 Correct 211 ms 45296 KB Output is correct
72 Correct 164 ms 41976 KB Output is correct
73 Correct 195 ms 48448 KB Output is correct
74 Correct 144 ms 40024 KB Output is correct
75 Correct 139 ms 41724 KB Output is correct
76 Correct 187 ms 40720 KB Output is correct
77 Correct 133 ms 39428 KB Output is correct
78 Correct 160 ms 39588 KB Output is correct
79 Correct 163 ms 41148 KB Output is correct
80 Correct 97 ms 40220 KB Output is correct
81 Correct 262 ms 45892 KB Output is correct
82 Correct 274 ms 46340 KB Output is correct
83 Correct 160 ms 41160 KB Output is correct
84 Correct 176 ms 39352 KB Output is correct
85 Correct 264 ms 45968 KB Output is correct
86 Correct 173 ms 41132 KB Output is correct
87 Correct 166 ms 41236 KB Output is correct
88 Correct 146 ms 39744 KB Output is correct
89 Correct 170 ms 39980 KB Output is correct
90 Correct 252 ms 43132 KB Output is correct
91 Correct 255 ms 43840 KB Output is correct
92 Correct 260 ms 45780 KB Output is correct
93 Correct 243 ms 47484 KB Output is correct
94 Correct 218 ms 43516 KB Output is correct
95 Correct 143 ms 42620 KB Output is correct
96 Correct 100 ms 41448 KB Output is correct
97 Correct 127 ms 31104 KB Output is correct
98 Correct 252 ms 47228 KB Output is correct
99 Correct 171 ms 39812 KB Output is correct
100 Correct 47 ms 20940 KB Output is correct
101 Correct 290 ms 44312 KB Output is correct
102 Correct 183 ms 38332 KB Output is correct
103 Correct 205 ms 38508 KB Output is correct
104 Correct 261 ms 42176 KB Output is correct