답안 #436613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436613 2021-06-24T16:54:18 Z dqhungdl 분수 공원 (IOI21_parks) C++17
30 / 100
829 ms 49800 KB
#include "parks.h"

#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
const int MAX=2e5+5;
int n,P[MAX];
vector<int> x,y;
map<ii,int> M;

bool isVertical(ii u) {
	return x[u.first]==x[u.second];
}

bool cmp(ii u,ii v) {
	if(x[u.first]==x[v.first]) {
		if(isVertical(u)==isVertical(v))
			return y[u.first]<y[v.first];
		return isVertical(u)>isVertical(v);
	}
	return x[u.first]<x[v.first];
}

vector<ii> constructBenches(vector<ii> &paths) {
	map<ii,bool> mark,under;
	vector<ii> benchesPos;
	for(int i=0;i<paths.size();i++) {
		ii path=paths[i];
		if(x[path.first]==x[path.second]) {
			int bx=x[path.first],by=y[path.first]+1;
			benchesPos.push_back({bx-1,by});
			benchesPos.push_back({bx+1,by});
			under[ii(bx-1,by)]=true;
		} else {
			int bx=x[path.first]+1,by=y[path.first];
			benchesPos.push_back({bx,by-1});
			benchesPos.push_back({bx,by+1});
		}
	}
		vector<ii> benches;
	if(*max_element(x.begin(),x.end())<=6) {
		for(int i=0;i<paths.size();i++) {
			if(!mark[benchesPos[2*i]]) {
				mark[benchesPos[2*i]]=true;
				benches.push_back(benchesPos[2*i]);
			} else {
				mark[benchesPos[2*i+1]]=true;
				benches.push_back(benchesPos[2*i+1]);
			}
		}
	} else {
		for(int i=0;i<paths.size();i++) {
			ii path=paths[i];
			if(x[path.first]==x[path.second]) { // Vertical
				if(!mark[benchesPos[2*i]]) {
					mark[benchesPos[2*i]]=true;
					benches.push_back(benchesPos[2*i]);
				} else {
					mark[benchesPos[2*i+1]]=true;
					benches.push_back(benchesPos[2*i+1]);
				}
			}
			else { // Horizontal
				if(mark[benchesPos[2*i]]||(under[benchesPos[2*i]]&&!under[benchesPos[2*i+1]])) {
					mark[benchesPos[2*i+1]]=true;
					benches.push_back(benchesPos[2*i+1]);
				} else {
					mark[benchesPos[2*i]]=true;
					benches.push_back(benchesPos[2*i]);
				}
			}
		}
	}
	return benches;
}

int find(int u) {
	if(u==P[u])
		return u;
	return P[u]=find(P[u]);
}

void merge(int u,int v) {
	if(u>v)
		swap(u,v);
	P[u]=v;
}

vector<ii> removePaths(vector<ii> paths) {
	for(int i=0;i<n;i++)
		P[i]=i;
	vector<ii> newPaths;
	for(ii path:paths) {
		int u=find(path.first),v=find(path.second);
		if(u!=v) {
			merge(u,v);
			newPaths.push_back(path);
		}
	}
	return newPaths;
}

int construct_roads(std::vector<int> _x, std::vector<int> _y) {
	n=_x.size();
	x=_x,y=_y;
	for(int i=0;i<n;i++)
		M[ii(x[i],y[i])]=i;
	vector<ii> paths;
	for(int i=0;i<n;i++) {
		auto it=M.find({x[i]+2,y[i]});
		if(it!=M.end())
			paths.push_back({i,it->second});
		it=M.find({x[i],y[i]+2});
		if(it!=M.end())
			paths.push_back({i,it->second});
	}
	sort(paths.begin(),paths.end(),cmp);
	paths = removePaths(paths);
	if(paths.size()!=n-1)
		return 0;
	//for(ii path:paths)
	//	cerr<<x[path.first]<<' '<<y[path.first]<<' '<<x[path.second]<<' '<<y[path.second]<<'\n';
	vector<ii> benches=constructBenches(paths);
	vector<int> U(n-1),V(n-1),A(n-1),B(n-1);
	for(int i=0;i<n-1;i++) {
		U[i]=paths[i].first,V[i]=paths[i].second;
		A[i]=benches[i].first,B[i]=benches[i].second;
	}
	build(U,V,A,B);
	return 1;
}

Compilation message

parks.cpp: In function 'std::vector<std::pair<int, int> > constructBenches(std::vector<std::pair<int, int> >&)':
parks.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for(int i=0;i<paths.size();i++) {
      |              ~^~~~~~~~~~~~~
parks.cpp:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for(int i=0;i<paths.size();i++) {
      |               ~^~~~~~~~~~~~~
parks.cpp:53:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int i=0;i<paths.size();i++) {
      |               ~^~~~~~~~~~~~~
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:120:17: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  120 |  if(paths.size()!=n-1)
      |     ~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 236 ms 24908 KB Output is correct
10 Correct 17 ms 2684 KB Output is correct
11 Correct 116 ms 13556 KB Output is correct
12 Correct 25 ms 3924 KB Output is correct
13 Correct 34 ms 5656 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 250 ms 24896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 236 ms 24908 KB Output is correct
10 Correct 17 ms 2684 KB Output is correct
11 Correct 116 ms 13556 KB Output is correct
12 Correct 25 ms 3924 KB Output is correct
13 Correct 34 ms 5656 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 250 ms 24896 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 679 ms 43380 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 4 ms 716 KB Output is correct
28 Correct 190 ms 17508 KB Output is correct
29 Correct 398 ms 26204 KB Output is correct
30 Correct 464 ms 34796 KB Output is correct
31 Correct 725 ms 43360 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 3 ms 588 KB Output is correct
45 Correct 251 ms 22928 KB Output is correct
46 Correct 439 ms 33356 KB Output is correct
47 Correct 494 ms 33356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 236 ms 24908 KB Output is correct
10 Correct 17 ms 2684 KB Output is correct
11 Correct 116 ms 13556 KB Output is correct
12 Correct 25 ms 3924 KB Output is correct
13 Correct 34 ms 5656 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 250 ms 24896 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 679 ms 43380 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 4 ms 716 KB Output is correct
28 Correct 190 ms 17508 KB Output is correct
29 Correct 398 ms 26204 KB Output is correct
30 Correct 464 ms 34796 KB Output is correct
31 Correct 725 ms 43360 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 3 ms 588 KB Output is correct
45 Correct 251 ms 22928 KB Output is correct
46 Correct 439 ms 33356 KB Output is correct
47 Correct 494 ms 33356 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 774 ms 42204 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 5 ms 588 KB Output is correct
58 Correct 14 ms 1516 KB Output is correct
59 Correct 14 ms 1640 KB Output is correct
60 Correct 278 ms 21248 KB Output is correct
61 Correct 416 ms 28664 KB Output is correct
62 Correct 583 ms 35328 KB Output is correct
63 Correct 707 ms 42196 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 1 ms 204 KB Output is correct
67 Correct 716 ms 49528 KB Output is correct
68 Correct 615 ms 49500 KB Output is correct
69 Correct 568 ms 49584 KB Output is correct
70 Correct 4 ms 716 KB Output is correct
71 Correct 8 ms 1256 KB Output is correct
72 Correct 265 ms 22672 KB Output is correct
73 Correct 454 ms 33996 KB Output is correct
74 Correct 658 ms 45212 KB Output is correct
75 Correct 629 ms 44668 KB Output is correct
76 Correct 588 ms 49580 KB Output is correct
77 Correct 6 ms 844 KB Output is correct
78 Correct 9 ms 1432 KB Output is correct
79 Correct 264 ms 22500 KB Output is correct
80 Correct 443 ms 33540 KB Output is correct
81 Correct 644 ms 44872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 236 ms 24908 KB Output is correct
10 Correct 17 ms 2684 KB Output is correct
11 Correct 116 ms 13556 KB Output is correct
12 Correct 25 ms 3924 KB Output is correct
13 Correct 34 ms 5656 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 250 ms 24896 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 678 ms 49696 KB Output is correct
21 Correct 646 ms 49640 KB Output is correct
22 Correct 645 ms 49600 KB Output is correct
23 Correct 600 ms 42224 KB Output is correct
24 Correct 350 ms 18256 KB Output is correct
25 Correct 491 ms 24560 KB Output is correct
26 Correct 431 ms 24520 KB Output is correct
27 Correct 661 ms 49608 KB Output is correct
28 Correct 613 ms 49536 KB Output is correct
29 Correct 705 ms 49512 KB Output is correct
30 Correct 829 ms 49652 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Incorrect 29 ms 3712 KB Tree @(185701, 20385) appears more than once: for edges on positions 143 and 151
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 236 ms 24908 KB Output is correct
10 Correct 17 ms 2684 KB Output is correct
11 Correct 116 ms 13556 KB Output is correct
12 Correct 25 ms 3924 KB Output is correct
13 Correct 34 ms 5656 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 250 ms 24896 KB Output is correct
17 Correct 631 ms 49800 KB Output is correct
18 Correct 662 ms 49524 KB Output is correct
19 Incorrect 674 ms 49580 KB Tree @(5, 50001) appears more than once: for edges on positions 1 and 3
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 236 ms 24908 KB Output is correct
10 Correct 17 ms 2684 KB Output is correct
11 Correct 116 ms 13556 KB Output is correct
12 Correct 25 ms 3924 KB Output is correct
13 Correct 34 ms 5656 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 250 ms 24896 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 679 ms 43380 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 4 ms 716 KB Output is correct
28 Correct 190 ms 17508 KB Output is correct
29 Correct 398 ms 26204 KB Output is correct
30 Correct 464 ms 34796 KB Output is correct
31 Correct 725 ms 43360 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 3 ms 588 KB Output is correct
45 Correct 251 ms 22928 KB Output is correct
46 Correct 439 ms 33356 KB Output is correct
47 Correct 494 ms 33356 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 774 ms 42204 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 5 ms 588 KB Output is correct
58 Correct 14 ms 1516 KB Output is correct
59 Correct 14 ms 1640 KB Output is correct
60 Correct 278 ms 21248 KB Output is correct
61 Correct 416 ms 28664 KB Output is correct
62 Correct 583 ms 35328 KB Output is correct
63 Correct 707 ms 42196 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 1 ms 204 KB Output is correct
67 Correct 716 ms 49528 KB Output is correct
68 Correct 615 ms 49500 KB Output is correct
69 Correct 568 ms 49584 KB Output is correct
70 Correct 4 ms 716 KB Output is correct
71 Correct 8 ms 1256 KB Output is correct
72 Correct 265 ms 22672 KB Output is correct
73 Correct 454 ms 33996 KB Output is correct
74 Correct 658 ms 45212 KB Output is correct
75 Correct 629 ms 44668 KB Output is correct
76 Correct 588 ms 49580 KB Output is correct
77 Correct 6 ms 844 KB Output is correct
78 Correct 9 ms 1432 KB Output is correct
79 Correct 264 ms 22500 KB Output is correct
80 Correct 443 ms 33540 KB Output is correct
81 Correct 644 ms 44872 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 678 ms 49696 KB Output is correct
86 Correct 646 ms 49640 KB Output is correct
87 Correct 645 ms 49600 KB Output is correct
88 Correct 600 ms 42224 KB Output is correct
89 Correct 350 ms 18256 KB Output is correct
90 Correct 491 ms 24560 KB Output is correct
91 Correct 431 ms 24520 KB Output is correct
92 Correct 661 ms 49608 KB Output is correct
93 Correct 613 ms 49536 KB Output is correct
94 Correct 705 ms 49512 KB Output is correct
95 Correct 829 ms 49652 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Incorrect 29 ms 3712 KB Tree @(185701, 20385) appears more than once: for edges on positions 143 and 151
98 Halted 0 ms 0 KB -