Submission #436591

# Submission time Handle Problem Language Result Execution time Memory
436591 2021-06-24T16:34:40 Z dqhungdl Fountain Parks (IOI21_parks) C++17
30 / 100
720 ms 39888 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;
	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});
		} 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;
	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]);
		}
	}
	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:41: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]
   41 |  for(int i=0;i<paths.size();i++) {
      |              ~^~~~~~~~~~~~~
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:95: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]
   95 |  if(paths.size()!=n-1)
      |     ~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory 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 214 ms 18708 KB Output is correct
10 Correct 14 ms 2060 KB Output is correct
11 Correct 83 ms 10108 KB Output is correct
12 Correct 24 ms 3020 KB Output is correct
13 Correct 45 ms 5664 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 214 ms 18580 KB Output is correct
# Verdict Execution time Memory 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 214 ms 18708 KB Output is correct
10 Correct 14 ms 2060 KB Output is correct
11 Correct 83 ms 10108 KB Output is correct
12 Correct 24 ms 3020 KB Output is correct
13 Correct 45 ms 5664 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 214 ms 18580 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 660 ms 39748 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 6 ms 716 KB Output is correct
28 Correct 202 ms 14956 KB Output is correct
29 Correct 343 ms 23944 KB Output is correct
30 Correct 479 ms 29628 KB Output is correct
31 Correct 720 ms 39812 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 304 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 227 ms 18648 KB Output is correct
46 Correct 391 ms 27240 KB Output is correct
47 Correct 384 ms 27196 KB Output is correct
# Verdict Execution time Memory 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 214 ms 18708 KB Output is correct
10 Correct 14 ms 2060 KB Output is correct
11 Correct 83 ms 10108 KB Output is correct
12 Correct 24 ms 3020 KB Output is correct
13 Correct 45 ms 5664 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 214 ms 18580 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 660 ms 39748 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 6 ms 716 KB Output is correct
28 Correct 202 ms 14956 KB Output is correct
29 Correct 343 ms 23944 KB Output is correct
30 Correct 479 ms 29628 KB Output is correct
31 Correct 720 ms 39812 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 304 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 227 ms 18648 KB Output is correct
46 Correct 391 ms 27240 KB Output is correct
47 Correct 384 ms 27196 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 636 ms 39888 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 3 ms 588 KB Output is correct
58 Correct 11 ms 1484 KB Output is correct
59 Correct 12 ms 1608 KB Output is correct
60 Correct 269 ms 19816 KB Output is correct
61 Correct 420 ms 25816 KB Output is correct
62 Correct 539 ms 32916 KB Output is correct
63 Correct 675 ms 39888 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 533 ms 37104 KB Output is correct
68 Correct 509 ms 37000 KB Output is correct
69 Correct 504 ms 36860 KB Output is correct
70 Correct 4 ms 716 KB Output is correct
71 Correct 8 ms 1228 KB Output is correct
72 Correct 223 ms 18600 KB Output is correct
73 Correct 413 ms 28012 KB Output is correct
74 Correct 571 ms 37008 KB Output is correct
75 Correct 613 ms 37344 KB Output is correct
76 Correct 515 ms 36988 KB Output is correct
77 Correct 5 ms 844 KB Output is correct
78 Correct 9 ms 1484 KB Output is correct
79 Correct 233 ms 18672 KB Output is correct
80 Correct 421 ms 27924 KB Output is correct
81 Correct 626 ms 37056 KB Output is correct
# Verdict Execution time Memory 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 214 ms 18708 KB Output is correct
10 Correct 14 ms 2060 KB Output is correct
11 Correct 83 ms 10108 KB Output is correct
12 Correct 24 ms 3020 KB Output is correct
13 Correct 45 ms 5664 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 214 ms 18580 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 557 ms 37044 KB Output is correct
21 Correct 591 ms 37116 KB Output is correct
22 Correct 600 ms 37244 KB Output is correct
23 Correct 443 ms 31564 KB Output is correct
24 Correct 369 ms 18376 KB Output is correct
25 Correct 459 ms 24508 KB Output is correct
26 Correct 430 ms 24552 KB Output is correct
27 Correct 576 ms 36992 KB Output is correct
28 Correct 595 ms 37380 KB Output is correct
29 Correct 682 ms 37076 KB Output is correct
30 Correct 687 ms 37088 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Incorrect 28 ms 2804 KB Tree @(185725, 20413) appears more than once: for edges on positions 631 and 647
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 214 ms 18708 KB Output is correct
10 Correct 14 ms 2060 KB Output is correct
11 Correct 83 ms 10108 KB Output is correct
12 Correct 24 ms 3020 KB Output is correct
13 Correct 45 ms 5664 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 214 ms 18580 KB Output is correct
17 Correct 571 ms 37008 KB Output is correct
18 Correct 578 ms 37016 KB Output is correct
19 Correct 637 ms 36992 KB Output is correct
20 Correct 658 ms 36344 KB Output is correct
21 Correct 488 ms 32444 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Incorrect 61 ms 6740 KB Tree @(185191, 20673) appears more than once: for edges on positions 1203 and 1221
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 214 ms 18708 KB Output is correct
10 Correct 14 ms 2060 KB Output is correct
11 Correct 83 ms 10108 KB Output is correct
12 Correct 24 ms 3020 KB Output is correct
13 Correct 45 ms 5664 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 214 ms 18580 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 660 ms 39748 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 6 ms 716 KB Output is correct
28 Correct 202 ms 14956 KB Output is correct
29 Correct 343 ms 23944 KB Output is correct
30 Correct 479 ms 29628 KB Output is correct
31 Correct 720 ms 39812 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 304 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 227 ms 18648 KB Output is correct
46 Correct 391 ms 27240 KB Output is correct
47 Correct 384 ms 27196 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 636 ms 39888 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 3 ms 588 KB Output is correct
58 Correct 11 ms 1484 KB Output is correct
59 Correct 12 ms 1608 KB Output is correct
60 Correct 269 ms 19816 KB Output is correct
61 Correct 420 ms 25816 KB Output is correct
62 Correct 539 ms 32916 KB Output is correct
63 Correct 675 ms 39888 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 533 ms 37104 KB Output is correct
68 Correct 509 ms 37000 KB Output is correct
69 Correct 504 ms 36860 KB Output is correct
70 Correct 4 ms 716 KB Output is correct
71 Correct 8 ms 1228 KB Output is correct
72 Correct 223 ms 18600 KB Output is correct
73 Correct 413 ms 28012 KB Output is correct
74 Correct 571 ms 37008 KB Output is correct
75 Correct 613 ms 37344 KB Output is correct
76 Correct 515 ms 36988 KB Output is correct
77 Correct 5 ms 844 KB Output is correct
78 Correct 9 ms 1484 KB Output is correct
79 Correct 233 ms 18672 KB Output is correct
80 Correct 421 ms 27924 KB Output is correct
81 Correct 626 ms 37056 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 557 ms 37044 KB Output is correct
86 Correct 591 ms 37116 KB Output is correct
87 Correct 600 ms 37244 KB Output is correct
88 Correct 443 ms 31564 KB Output is correct
89 Correct 369 ms 18376 KB Output is correct
90 Correct 459 ms 24508 KB Output is correct
91 Correct 430 ms 24552 KB Output is correct
92 Correct 576 ms 36992 KB Output is correct
93 Correct 595 ms 37380 KB Output is correct
94 Correct 682 ms 37076 KB Output is correct
95 Correct 687 ms 37088 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Incorrect 28 ms 2804 KB Tree @(185725, 20413) appears more than once: for edges on positions 631 and 647
98 Halted 0 ms 0 KB -