답안 #1052836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052836 2024-08-11T04:21:53 Z ReLice 분수 공원 (IOI21_parks) C++17
30 / 100
373 ms 56836 KB
#include "parks.h"
#include <bits/stdc++.h>
#define ll int
#define vll vector<ll>
#define fr first
#define sc second
#define pb push_back
#define sz size()
#define bc back()
#define all(x) x.begin(),x.end()
using namespace std;
const int N=2e5+5;
const int inf=1e9;
ll p[N],siz[N];
map<pair<ll,ll>,bool> vis;
map<pair<ll,ll>,ll> f;
ll anc(ll a){
	return (p[a]==a ? a : p[a]=anc(p[a]));
}
bool uni(ll a,ll b){
	a=anc(a);
	b=anc(b);
	if(a==b)return false;
	if(siz[a]>siz[b])swap(a,b);
	p[a]=b;
	siz[b]+=siz[a];
	return true;
}
int construct_roads(vector<int> x, vector<int> y) {
	vis[{x[0],y[0]}]=1;
	vector<pair<ll,pair<ll,ll>>> ver,hor;
	ll n=x.size();
	ll i;
	for(i=0;i<(int)x.size();i++){
		f[{x[i],y[i]}]=i+1;
	}
	for(i=0;i<n;i++){
		p[i]=i;
		siz[i]=1;
		if(f[{x[i]+2,y[i]+0}]){
			hor.pb({x[i],{i,f[{x[i]+2,y[i]+0}]-1}});
		}if(f[{x[i]+0,y[i]+2}]){
			ver.pb({x[i],{i,f[{x[i]+0,y[i]+2}]-1}});
		}
	}
	sort(all(ver));
	sort(all(hor));
	vll U,V,A,B;
	while(ver.sz || hor.sz){
		ll xx;
		if(ver.sz && hor.sz)xx=max(ver.bc.fr,hor.bc.fr);
		else if(ver.sz) xx=ver.bc.fr;
		else xx=hor.bc.fr;
		while(hor.sz && hor.bc.fr==xx){
			ll a=hor.bc.sc.fr,b=hor.bc.sc.sc;
			hor.pop_back();
			if(anc(a)!=anc(b)){
				if(vis[{x[a]+1,y[a]-1}]==0){
					vis[{x[a]+1,y[a]-1}]=1;
					uni(a,b);
					U.pb(a);
					V.pb(b);
					A.pb(x[a]+1);
					B.pb(y[a]-1);
				}
				else if(vis[{x[a]+1,y[a]+1}]==0){
					vis[{x[a]+1,y[a]+1}]=1;
					uni(a,b);
					U.pb(a);
					V.pb(b);
					A.pb(x[a]+1);
					B.pb(y[a]+1);
				}
			}
		}
		while(ver.sz && ver.bc.fr==xx){
			ll a=ver.bc.sc.fr,b=ver.bc.sc.sc;
			ver.pop_back();
			if(anc(a)!=anc(b)){
				if(vis[{x[a]+1,y[a]+1}]==0){
					vis[{x[a]+1,y[a]+1}]=1;
					uni(a,b);
					U.pb(a);
					V.pb(b);
					A.pb(x[a]+1);
					B.pb(y[a]+1);
				}
				else if(vis[{x[a]-1,y[a]+1}]==0){
					vis[{x[a]-1,y[a]+1}]=1;
					uni(a,b);
					U.pb(a);
					V.pb(b);
					A.pb(x[a]-1);
					B.pb(y[a]+1);
					
				}
			}
		}
	}
	if((int)V.size()!=n-1)return 0;
	
	//~ for(int i=0;i<(int)V.size();i++)cout<<V[i]<<' '<<V[i]<<endl;
	//~ for(auto i : A)cout<<i<<' ';
	//~ cout<<endl;
	//~ for(auto i : B)cout<<i<<' ';
	//~ cout<<endl;
	build(U,V,A,B);
    return 1;
}











# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 152 ms 27592 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 45 ms 15020 KB Output is correct
12 Correct 11 ms 4520 KB Output is correct
13 Correct 31 ms 10964 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 146 ms 27496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 152 ms 27592 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 45 ms 15020 KB Output is correct
12 Correct 11 ms 4520 KB Output is correct
13 Correct 31 ms 10964 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 146 ms 27496 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 336 ms 51212 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 1048 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 113 ms 20648 KB Output is correct
29 Correct 188 ms 30652 KB Output is correct
30 Correct 274 ms 41348 KB Output is correct
31 Correct 338 ms 51628 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 712 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 146 ms 28016 KB Output is correct
46 Correct 249 ms 39812 KB Output is correct
47 Correct 246 ms 39988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 152 ms 27592 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 45 ms 15020 KB Output is correct
12 Correct 11 ms 4520 KB Output is correct
13 Correct 31 ms 10964 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 146 ms 27496 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 336 ms 51212 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 1048 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 113 ms 20648 KB Output is correct
29 Correct 188 ms 30652 KB Output is correct
30 Correct 274 ms 41348 KB Output is correct
31 Correct 338 ms 51628 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 712 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 146 ms 28016 KB Output is correct
46 Correct 249 ms 39812 KB Output is correct
47 Correct 246 ms 39988 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 444 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 349 ms 49560 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 6 ms 1884 KB Output is correct
59 Correct 9 ms 2392 KB Output is correct
60 Correct 139 ms 24868 KB Output is correct
61 Correct 201 ms 34648 KB Output is correct
62 Correct 263 ms 41020 KB Output is correct
63 Correct 334 ms 50352 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 373 ms 56632 KB Output is correct
68 Correct 352 ms 56748 KB Output is correct
69 Correct 364 ms 56336 KB Output is correct
70 Correct 3 ms 1368 KB Output is correct
71 Correct 7 ms 2228 KB Output is correct
72 Correct 145 ms 27076 KB Output is correct
73 Correct 253 ms 40640 KB Output is correct
74 Correct 372 ms 53432 KB Output is correct
75 Correct 333 ms 52604 KB Output is correct
76 Correct 355 ms 56836 KB Output is correct
77 Correct 4 ms 1368 KB Output is correct
78 Correct 8 ms 2488 KB Output is correct
79 Correct 145 ms 26376 KB Output is correct
80 Correct 240 ms 40124 KB Output is correct
81 Correct 344 ms 53684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 152 ms 27592 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 45 ms 15020 KB Output is correct
12 Correct 11 ms 4520 KB Output is correct
13 Correct 31 ms 10964 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 146 ms 27496 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 260 ms 48456 KB Output is correct
21 Correct 305 ms 54716 KB Output is correct
22 Correct 266 ms 48312 KB Output is correct
23 Correct 249 ms 46528 KB Output is correct
24 Correct 249 ms 42648 KB Output is correct
25 Correct 289 ms 48316 KB Output is correct
26 Correct 286 ms 48432 KB Output is correct
27 Correct 334 ms 54924 KB Output is correct
28 Correct 330 ms 54852 KB Output is correct
29 Correct 321 ms 54964 KB Output is correct
30 Correct 309 ms 55044 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Incorrect 13 ms 3512 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 152 ms 27592 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 45 ms 15020 KB Output is correct
12 Correct 11 ms 4520 KB Output is correct
13 Correct 31 ms 10964 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 146 ms 27496 KB Output is correct
17 Correct 320 ms 54644 KB Output is correct
18 Correct 315 ms 54716 KB Output is correct
19 Correct 295 ms 51560 KB Output is correct
20 Correct 303 ms 46268 KB Output is correct
21 Correct 281 ms 46012 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Incorrect 32 ms 7080 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 152 ms 27592 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 45 ms 15020 KB Output is correct
12 Correct 11 ms 4520 KB Output is correct
13 Correct 31 ms 10964 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 146 ms 27496 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 336 ms 51212 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 1048 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 113 ms 20648 KB Output is correct
29 Correct 188 ms 30652 KB Output is correct
30 Correct 274 ms 41348 KB Output is correct
31 Correct 338 ms 51628 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 712 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 146 ms 28016 KB Output is correct
46 Correct 249 ms 39812 KB Output is correct
47 Correct 246 ms 39988 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 444 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 349 ms 49560 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 6 ms 1884 KB Output is correct
59 Correct 9 ms 2392 KB Output is correct
60 Correct 139 ms 24868 KB Output is correct
61 Correct 201 ms 34648 KB Output is correct
62 Correct 263 ms 41020 KB Output is correct
63 Correct 334 ms 50352 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 373 ms 56632 KB Output is correct
68 Correct 352 ms 56748 KB Output is correct
69 Correct 364 ms 56336 KB Output is correct
70 Correct 3 ms 1368 KB Output is correct
71 Correct 7 ms 2228 KB Output is correct
72 Correct 145 ms 27076 KB Output is correct
73 Correct 253 ms 40640 KB Output is correct
74 Correct 372 ms 53432 KB Output is correct
75 Correct 333 ms 52604 KB Output is correct
76 Correct 355 ms 56836 KB Output is correct
77 Correct 4 ms 1368 KB Output is correct
78 Correct 8 ms 2488 KB Output is correct
79 Correct 145 ms 26376 KB Output is correct
80 Correct 240 ms 40124 KB Output is correct
81 Correct 344 ms 53684 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 260 ms 48456 KB Output is correct
86 Correct 305 ms 54716 KB Output is correct
87 Correct 266 ms 48312 KB Output is correct
88 Correct 249 ms 46528 KB Output is correct
89 Correct 249 ms 42648 KB Output is correct
90 Correct 289 ms 48316 KB Output is correct
91 Correct 286 ms 48432 KB Output is correct
92 Correct 334 ms 54924 KB Output is correct
93 Correct 330 ms 54852 KB Output is correct
94 Correct 321 ms 54964 KB Output is correct
95 Correct 309 ms 55044 KB Output is correct
96 Correct 1 ms 344 KB Output is correct
97 Incorrect 13 ms 3512 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -