Submission #651744

# Submission time Handle Problem Language Result Execution time Memory
651744 2022-10-19T23:29:46 Z inksamurai Stranded Far From Home (BOI22_island) C++17
100 / 100
288 ms 47116 KB
#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3CZAtRo ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

struct dsu{
	int n,cmps;
	vi par,si,leb;
	vec(vi) rbts;
	// vec(set<pii>) evs;
	dsu(int _n=0){init(_n);}
	void init(int _n){
		n=_n;
		cmps=n;
		par.clear();
		si.clear();
		leb.clear();
		rbts.clear();
		// evs.clear();
		par.resize(n);
		si.resize(n);
		leb.resize(n);
		rbts.resize(n);
		// evs.resize(n);
		rep(i,n){
			par[i]=i;
			si[i]=1;
			rbts[i].pb(i);
		}
	}
	void merge(int a,int b){
		if(same(a,b)) return;
		cmps-=1;
		int u=parent(a);
		int v=parent(b);
		if(si[u]<si[v])swap(u,v);
		// for(auto p:evs[v]){
		// 	evs[u].insert(p);
		// }
		for(auto x:rbts[v]){
			rbts[u].pb(x);
		}
		leb[u]+=leb[v];
		si[u]+=si[v];
		par[v]=u;
	}
	int parent(int v){return par[v]=par[v]==v?v:parent(par[v]);}
	bool same(int u,int v){return parent(v)==parent(u);}
	int size(int v=-1){return v==-1?cmps:si[parent(v)];}
};

signed main(){
_3CZAtRo;
	int n,m;
	cin>>n>>m;

	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	vec(vi) adj(n);
	rep(_,m){
		int u,v;
		cin>>u>>v;
		u-=1,v-=1;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dsu uf(n);
	rep(v,n){
		uf.leb[v]=a[v];
	}

	vi ert;
	rep(i,n){
		ert.pb(i);		
	}
	sort(ert.begin(),ert.end(),[&](const int&l,const int&r){
		return a[l]<a[r];
	});

	vi pns(n,1);
	rep(i,n){
		int v=ert[i];
		for(auto u:adj[v]){
			if(a[v]>=a[u]){
				int up=uf.parent(u);
				int now=uf.leb[up];
				if(now<a[v]){
					for(auto rbt:uf.rbts[up]){
						pns[rbt]=0;
					}
					uf.rbts[up].clear();
				}
				uf.merge(v,up);
			}
		}
	}

	rep(i,n){
		cout<<pns[i];
	}
	print();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 175 ms 35784 KB Output is correct
4 Correct 167 ms 43968 KB Output is correct
5 Correct 239 ms 42372 KB Output is correct
6 Correct 211 ms 44064 KB Output is correct
7 Correct 224 ms 43968 KB Output is correct
8 Correct 235 ms 43720 KB Output is correct
9 Correct 172 ms 47116 KB Output is correct
10 Correct 188 ms 37052 KB Output is correct
11 Correct 132 ms 39620 KB Output is correct
12 Correct 225 ms 39528 KB Output is correct
13 Correct 181 ms 44616 KB Output is correct
14 Correct 177 ms 43344 KB Output is correct
15 Correct 163 ms 39092 KB Output is correct
16 Correct 104 ms 38076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 243 ms 39868 KB Output is correct
3 Correct 248 ms 44728 KB Output is correct
4 Correct 159 ms 46132 KB Output is correct
5 Correct 172 ms 45132 KB Output is correct
6 Correct 242 ms 44344 KB Output is correct
7 Correct 161 ms 39100 KB Output is correct
8 Correct 180 ms 39264 KB Output is correct
9 Correct 100 ms 38112 KB Output is correct
10 Correct 153 ms 39908 KB Output is correct
11 Correct 198 ms 42252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 252 ms 36232 KB Output is correct
3 Correct 269 ms 41776 KB Output is correct
4 Correct 280 ms 43428 KB Output is correct
5 Correct 247 ms 45972 KB Output is correct
6 Correct 239 ms 41492 KB Output is correct
7 Correct 173 ms 40632 KB Output is correct
8 Correct 117 ms 41456 KB Output is correct
9 Correct 139 ms 22432 KB Output is correct
10 Correct 271 ms 46152 KB Output is correct
11 Correct 229 ms 42432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 175 ms 35784 KB Output is correct
18 Correct 167 ms 43968 KB Output is correct
19 Correct 239 ms 42372 KB Output is correct
20 Correct 211 ms 44064 KB Output is correct
21 Correct 224 ms 43968 KB Output is correct
22 Correct 235 ms 43720 KB Output is correct
23 Correct 172 ms 47116 KB Output is correct
24 Correct 188 ms 37052 KB Output is correct
25 Correct 132 ms 39620 KB Output is correct
26 Correct 225 ms 39528 KB Output is correct
27 Correct 181 ms 44616 KB Output is correct
28 Correct 177 ms 43344 KB Output is correct
29 Correct 163 ms 39092 KB Output is correct
30 Correct 104 ms 38076 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 243 ms 39868 KB Output is correct
33 Correct 248 ms 44728 KB Output is correct
34 Correct 159 ms 46132 KB Output is correct
35 Correct 172 ms 45132 KB Output is correct
36 Correct 242 ms 44344 KB Output is correct
37 Correct 161 ms 39100 KB Output is correct
38 Correct 180 ms 39264 KB Output is correct
39 Correct 100 ms 38112 KB Output is correct
40 Correct 153 ms 39908 KB Output is correct
41 Correct 198 ms 42252 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 252 ms 36232 KB Output is correct
44 Correct 269 ms 41776 KB Output is correct
45 Correct 280 ms 43428 KB Output is correct
46 Correct 247 ms 45972 KB Output is correct
47 Correct 239 ms 41492 KB Output is correct
48 Correct 173 ms 40632 KB Output is correct
49 Correct 117 ms 41456 KB Output is correct
50 Correct 139 ms 22432 KB Output is correct
51 Correct 271 ms 46152 KB Output is correct
52 Correct 229 ms 42432 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 2 ms 596 KB Output is correct
57 Correct 3 ms 596 KB Output is correct
58 Correct 2 ms 620 KB Output is correct
59 Correct 2 ms 596 KB Output is correct
60 Correct 2 ms 596 KB Output is correct
61 Correct 2 ms 696 KB Output is correct
62 Correct 3 ms 716 KB Output is correct
63 Correct 3 ms 724 KB Output is correct
64 Correct 2 ms 724 KB Output is correct
65 Correct 2 ms 724 KB Output is correct
66 Correct 2 ms 596 KB Output is correct
67 Correct 180 ms 40220 KB Output is correct
68 Correct 198 ms 43968 KB Output is correct
69 Correct 225 ms 42368 KB Output is correct
70 Correct 228 ms 43836 KB Output is correct
71 Correct 218 ms 43968 KB Output is correct
72 Correct 242 ms 43716 KB Output is correct
73 Correct 181 ms 47108 KB Output is correct
74 Correct 178 ms 37048 KB Output is correct
75 Correct 153 ms 39708 KB Output is correct
76 Correct 216 ms 39620 KB Output is correct
77 Correct 165 ms 44572 KB Output is correct
78 Correct 168 ms 43268 KB Output is correct
79 Correct 141 ms 39124 KB Output is correct
80 Correct 109 ms 38080 KB Output is correct
81 Correct 240 ms 44292 KB Output is correct
82 Correct 244 ms 44600 KB Output is correct
83 Correct 198 ms 46256 KB Output is correct
84 Correct 158 ms 45000 KB Output is correct
85 Correct 244 ms 44272 KB Output is correct
86 Correct 189 ms 39232 KB Output is correct
87 Correct 172 ms 39180 KB Output is correct
88 Correct 161 ms 39992 KB Output is correct
89 Correct 182 ms 42264 KB Output is correct
90 Correct 273 ms 40760 KB Output is correct
91 Correct 259 ms 41788 KB Output is correct
92 Correct 254 ms 43452 KB Output is correct
93 Correct 242 ms 45968 KB Output is correct
94 Correct 249 ms 41504 KB Output is correct
95 Correct 139 ms 40648 KB Output is correct
96 Correct 116 ms 41480 KB Output is correct
97 Correct 126 ms 22464 KB Output is correct
98 Correct 239 ms 46172 KB Output is correct
99 Correct 190 ms 42392 KB Output is correct
100 Correct 42 ms 7080 KB Output is correct
101 Correct 284 ms 42308 KB Output is correct
102 Correct 201 ms 34828 KB Output is correct
103 Correct 245 ms 34312 KB Output is correct
104 Correct 288 ms 39684 KB Output is correct