Submission #710931

# Submission time Handle Problem Language Result Execution time Memory
710931 2023-03-16T05:34:47 Z emptypringlescan Stranded Far From Home (BOI22_island) C++17
100 / 100
307 ms 41256 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int par[200005];
long long men[200005];
vector<int> sz[200005];
int find(int x){
	if(par[x]==x) return x;
	return par[x]=find(par[x]);
}
void merge(int x, int y){
	if(find(x)==find(y)) return;
	x=find(x); y=find(y);
	assert(x<200005&&y<200005);
	if(sz[x].size()<=sz[y].size()){
		for(int i:sz[x]) sz[y].push_back(i);
		sz[x].clear();
	}
	else{
		for(int i:sz[y]) sz[x].push_back(i);
		swap(sz[x],sz[y]);
		sz[x].clear();
	}
	men[y]+=men[x];
	men[x]=0;
	par[x]=y;
}
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	for(int i=0; i<200005; i++) par[i]=i;
	int n,m;
	cin >> n >> m;
	pair<long long,int> arr[n];
	for(int i=0; i<n; i++){
		cin >> arr[i].first;
		arr[i].second=i;
	}
	sort(arr,arr+n);
	vector<int> adj[n];
	for(int i=0; i<m; i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int ans[n],on[n];
	for(int i=0; i<n; i++){
		ans[i]=1;
		on[i]=0;
	}
	for(int k=0; k<n; k++){
		int nd=arr[k].second;
		on[nd]=1;
		men[nd]=arr[k].first;
		sz[nd].push_back(nd);
		for(int i:adj[nd]){
			if(!on[i]) continue;
			if((int)men[find(i)]<arr[k].first){
				for(int j:sz[find(i)]) ans[j]=0;
				sz[find(i)].clear();
			}
			merge(i,nd);
		}
	}
	for(int i=0; i<n; i++) cout << ans[i];
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 5 ms 6740 KB Output is correct
5 Correct 5 ms 6868 KB Output is correct
6 Correct 5 ms 6740 KB Output is correct
7 Correct 5 ms 6740 KB Output is correct
8 Correct 4 ms 6736 KB Output is correct
9 Correct 5 ms 6868 KB Output is correct
10 Correct 4 ms 6868 KB Output is correct
11 Correct 5 ms 6868 KB Output is correct
12 Correct 5 ms 6868 KB Output is correct
13 Correct 4 ms 6868 KB Output is correct
14 Correct 4 ms 6868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 166 ms 34368 KB Output is correct
4 Correct 149 ms 35260 KB Output is correct
5 Correct 198 ms 36356 KB Output is correct
6 Correct 224 ms 37532 KB Output is correct
7 Correct 211 ms 37500 KB Output is correct
8 Correct 172 ms 34232 KB Output is correct
9 Correct 162 ms 40936 KB Output is correct
10 Correct 158 ms 33320 KB Output is correct
11 Correct 137 ms 34920 KB Output is correct
12 Correct 212 ms 34604 KB Output is correct
13 Correct 149 ms 35880 KB Output is correct
14 Correct 172 ms 35680 KB Output is correct
15 Correct 143 ms 33300 KB Output is correct
16 Correct 93 ms 33044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 267 ms 38032 KB Output is correct
3 Correct 266 ms 38328 KB Output is correct
4 Correct 173 ms 33376 KB Output is correct
5 Correct 155 ms 34140 KB Output is correct
6 Correct 280 ms 38244 KB Output is correct
7 Correct 165 ms 33424 KB Output is correct
8 Correct 168 ms 33368 KB Output is correct
9 Correct 104 ms 32996 KB Output is correct
10 Correct 141 ms 33840 KB Output is correct
11 Correct 202 ms 34256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 307 ms 35284 KB Output is correct
3 Correct 299 ms 36056 KB Output is correct
4 Correct 266 ms 37984 KB Output is correct
5 Correct 262 ms 39756 KB Output is correct
6 Correct 201 ms 35532 KB Output is correct
7 Correct 147 ms 34836 KB Output is correct
8 Correct 104 ms 36264 KB Output is correct
9 Correct 123 ms 22800 KB Output is correct
10 Correct 247 ms 41256 KB Output is correct
11 Correct 194 ms 34092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 5 ms 6740 KB Output is correct
5 Correct 5 ms 6868 KB Output is correct
6 Correct 5 ms 6740 KB Output is correct
7 Correct 5 ms 6740 KB Output is correct
8 Correct 4 ms 6736 KB Output is correct
9 Correct 5 ms 6868 KB Output is correct
10 Correct 4 ms 6868 KB Output is correct
11 Correct 5 ms 6868 KB Output is correct
12 Correct 5 ms 6868 KB Output is correct
13 Correct 4 ms 6868 KB Output is correct
14 Correct 4 ms 6868 KB Output is correct
15 Correct 3 ms 6484 KB Output is correct
16 Correct 3 ms 6484 KB Output is correct
17 Correct 166 ms 34368 KB Output is correct
18 Correct 149 ms 35260 KB Output is correct
19 Correct 198 ms 36356 KB Output is correct
20 Correct 224 ms 37532 KB Output is correct
21 Correct 211 ms 37500 KB Output is correct
22 Correct 172 ms 34232 KB Output is correct
23 Correct 162 ms 40936 KB Output is correct
24 Correct 158 ms 33320 KB Output is correct
25 Correct 137 ms 34920 KB Output is correct
26 Correct 212 ms 34604 KB Output is correct
27 Correct 149 ms 35880 KB Output is correct
28 Correct 172 ms 35680 KB Output is correct
29 Correct 143 ms 33300 KB Output is correct
30 Correct 93 ms 33044 KB Output is correct
31 Correct 4 ms 6484 KB Output is correct
32 Correct 267 ms 38032 KB Output is correct
33 Correct 266 ms 38328 KB Output is correct
34 Correct 173 ms 33376 KB Output is correct
35 Correct 155 ms 34140 KB Output is correct
36 Correct 280 ms 38244 KB Output is correct
37 Correct 165 ms 33424 KB Output is correct
38 Correct 168 ms 33368 KB Output is correct
39 Correct 104 ms 32996 KB Output is correct
40 Correct 141 ms 33840 KB Output is correct
41 Correct 202 ms 34256 KB Output is correct
42 Correct 4 ms 6484 KB Output is correct
43 Correct 307 ms 35284 KB Output is correct
44 Correct 299 ms 36056 KB Output is correct
45 Correct 266 ms 37984 KB Output is correct
46 Correct 262 ms 39756 KB Output is correct
47 Correct 201 ms 35532 KB Output is correct
48 Correct 147 ms 34836 KB Output is correct
49 Correct 104 ms 36264 KB Output is correct
50 Correct 123 ms 22800 KB Output is correct
51 Correct 247 ms 41256 KB Output is correct
52 Correct 194 ms 34092 KB Output is correct
53 Correct 3 ms 6484 KB Output is correct
54 Correct 3 ms 6484 KB Output is correct
55 Correct 3 ms 6484 KB Output is correct
56 Correct 4 ms 6740 KB Output is correct
57 Correct 4 ms 6868 KB Output is correct
58 Correct 5 ms 6740 KB Output is correct
59 Correct 4 ms 6740 KB Output is correct
60 Correct 4 ms 6740 KB Output is correct
61 Correct 4 ms 6888 KB Output is correct
62 Correct 5 ms 6868 KB Output is correct
63 Correct 7 ms 6868 KB Output is correct
64 Correct 4 ms 6868 KB Output is correct
65 Correct 5 ms 6868 KB Output is correct
66 Correct 5 ms 6868 KB Output is correct
67 Correct 154 ms 34376 KB Output is correct
68 Correct 161 ms 35328 KB Output is correct
69 Correct 193 ms 36412 KB Output is correct
70 Correct 275 ms 37476 KB Output is correct
71 Correct 217 ms 37488 KB Output is correct
72 Correct 163 ms 34256 KB Output is correct
73 Correct 168 ms 40952 KB Output is correct
74 Correct 165 ms 33336 KB Output is correct
75 Correct 160 ms 34988 KB Output is correct
76 Correct 239 ms 34604 KB Output is correct
77 Correct 157 ms 35968 KB Output is correct
78 Correct 143 ms 35708 KB Output is correct
79 Correct 154 ms 33324 KB Output is correct
80 Correct 125 ms 33012 KB Output is correct
81 Correct 276 ms 38072 KB Output is correct
82 Correct 280 ms 38496 KB Output is correct
83 Correct 177 ms 33360 KB Output is correct
84 Correct 152 ms 34144 KB Output is correct
85 Correct 261 ms 38160 KB Output is correct
86 Correct 157 ms 33340 KB Output is correct
87 Correct 147 ms 33340 KB Output is correct
88 Correct 133 ms 33844 KB Output is correct
89 Correct 216 ms 34320 KB Output is correct
90 Correct 254 ms 35296 KB Output is correct
91 Correct 247 ms 36064 KB Output is correct
92 Correct 283 ms 37972 KB Output is correct
93 Correct 243 ms 39636 KB Output is correct
94 Correct 230 ms 35548 KB Output is correct
95 Correct 149 ms 34876 KB Output is correct
96 Correct 102 ms 36200 KB Output is correct
97 Correct 113 ms 22832 KB Output is correct
98 Correct 214 ms 41212 KB Output is correct
99 Correct 186 ms 34120 KB Output is correct
100 Correct 46 ms 11372 KB Output is correct
101 Correct 303 ms 36492 KB Output is correct
102 Correct 239 ms 30036 KB Output is correct
103 Correct 230 ms 30172 KB Output is correct
104 Correct 285 ms 34368 KB Output is correct