Submission #831643

# Submission time Handle Problem Language Result Execution time Memory
831643 2023-08-20T11:47:31 Z andrey27_sm Fountain Parks (IOI21_parks) C++17
30 / 100
249 ms 47288 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> cons[200001];
int mask_l[200001];
vector<int> u;
vector<int> v;
vector<int> a;
vector<int> b;
struct dsu{
	int sz = 0;
	vector<int> pr;
	int p(int v){
		if(pr[v] == v) return v;
		return pr[v] = p(pr[v]);
	}
	bool un(int u,int v){
		u = p(u);
		v = p(v);
		if(u == v) return 0 ;
		pr[u] = v;
		sz++;
		return 1;
	}
} D;
struct edge{
	int x;
	int y;
	int type; // 0 - vert, 1 - hor;
	int a;
	int b;
};
int construct_roads(vector<int> x, vector<int> y) {
	int n = x.size();
	D.pr.resize(n);
	for (int i = 0; i < n; ++i)
	{
		D.pr[i] = i;
	}
	vector<edge> E;
	vector<pair<int,pair<int,int>>> x_d;
	vector<pair<int,pair<int,int>>> y_d;
	for (int i = 0; i < n; ++i)
	{
	 	x_d.push_back({x[i],{y[i],i}});
	 	y_d.push_back({y[i],{x[i],i}});
	} 
	sort(x_d.begin(), x_d.end());
	sort(y_d.begin(), y_d.end());
	for (int i = 1; i < n; ++i)
	{
		if(x_d[i].first == x_d[i-1].first and x_d[i].second.first-2 == x_d[i-1].second.first){
			if(D.un(x_d[i-1].second.second,x_d[i].second.second))
				E.push_back({x_d[i-1].first,x_d[i-1].second.first,0,x_d[i-1].second.second,x_d[i].second.second});
		}
	}
	for (int i = 1; i < n; ++i)
	{
		if(y_d[i].first == y_d[i-1].first and y_d[i].second.first-2 == y_d[i-1].second.first){
			if(D.un(y_d[i-1].second.second,y_d[i].second.second))
				E.push_back({y_d[i-1].second.first,y_d[i-1].first,1,y_d[i-1].second.second,y_d[i].second.second});
			
		}
	}
	if(D.sz != n-1) return 0;
	set<pair<int,int>> lines;
	set<pair<int,int>> points;
	sort(E.begin(),E.end(),[](auto a,auto b){
		if(a.x != b.x) return a.x < b.x;
		if(a.type != b.type) return a.type < b.type;
		return a.y < b.y;
	});
	for (int i = 0; i < E.size(); ++i)
	{
		if(E[i].type == 0) lines.insert({E[i].x,E[i].y});
	}
	assert(E.size() <= n-1);
	for (int i = 0; i < E.size(); ++i)
	{
		//cout << E[i].x << " " << E[i].y << "   --\n";
		if(E[i].type == 0){
			if(points.count({E[i].x-1,E[i].y+1}) == 0){
				u.push_back(E[i].a);
				v.push_back(E[i].b);
				a.push_back(E[i].x-1);
				b.push_back(E[i].y+1);
				points.insert({E[i].x-1,E[i].y+1});
			}
			else if(points.count({E[i].x+1,E[i].y+1}) == 0){				
				u.push_back(E[i].a);
				v.push_back(E[i].b);
				a.push_back(E[i].x+1);
				b.push_back(E[i].y+1);
				points.insert({E[i].x+1,E[i].y+1});
			}
			else return 0;
		}
		else{
			int top = 0;
			if(points.count({E[i].x+1,E[i].y-1})) top = 1;
			else if(points.count({E[i].x+1,E[i].y+1})) top = 2;
			if(top == 0 and ((lines.count({E[i].x+2,E[i].y-2}) and lines.count({E[i].x+2,E[i].y})) or lines.count({E[i].x+2,E[i].y}))) top = 2;
			if(top == 0 and lines.count({E[i].x+2,E[i].y-2})) top = 1;
			if(top%2 == 0){
				u.push_back(E[i].a);
				v.push_back(E[i].b);
				a.push_back(E[i].x+1);
				b.push_back(E[i].y-1);
				points.insert({E[i].x+1,E[i].y-1});
			}
			else{				
				u.push_back(E[i].a);
				v.push_back(E[i].b);
				a.push_back(E[i].x+1);
				b.push_back(E[i].y+1);
				points.insert({E[i].x+1,E[i].y+1});
			}
		}
	}
	if(points.size() != n-1) return 0;
	build(u,v,a,b);
	return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:73:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for (int i = 0; i < E.size(); ++i)
      |                  ~~^~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from parks.cpp:2:
parks.cpp:77:18: warning: comparison of integer expressions of different signedness: 'std::vector<edge>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   77 |  assert(E.size() <= n-1);
      |         ~~~~~~~~~^~~~~~
parks.cpp:78:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |  for (int i = 0; i < E.size(); ++i)
      |                  ~~^~~~~~~~~~
parks.cpp:120:19: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  120 |  if(points.size() != n-1) return 0;
      |     ~~~~~~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4932 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 105 ms 25416 KB Output is correct
10 Correct 9 ms 7056 KB Output is correct
11 Correct 45 ms 15904 KB Output is correct
12 Correct 14 ms 8024 KB Output is correct
13 Correct 12 ms 8804 KB Output is correct
14 Correct 2 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 102 ms 25460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4932 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 105 ms 25416 KB Output is correct
10 Correct 9 ms 7056 KB Output is correct
11 Correct 45 ms 15904 KB Output is correct
12 Correct 14 ms 8024 KB Output is correct
13 Correct 12 ms 8804 KB Output is correct
14 Correct 2 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 102 ms 25460 KB Output is correct
17 Correct 2 ms 5000 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 223 ms 47276 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 3 ms 5204 KB Output is correct
27 Correct 4 ms 5332 KB Output is correct
28 Correct 84 ms 21952 KB Output is correct
29 Correct 127 ms 30268 KB Output is correct
30 Correct 178 ms 38932 KB Output is correct
31 Correct 232 ms 47280 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 2 ms 4948 KB Output is correct
40 Correct 2 ms 4948 KB Output is correct
41 Correct 2 ms 4948 KB Output is correct
42 Correct 2 ms 4948 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5204 KB Output is correct
45 Correct 107 ms 24048 KB Output is correct
46 Correct 162 ms 33220 KB Output is correct
47 Correct 173 ms 33284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4932 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 105 ms 25416 KB Output is correct
10 Correct 9 ms 7056 KB Output is correct
11 Correct 45 ms 15904 KB Output is correct
12 Correct 14 ms 8024 KB Output is correct
13 Correct 12 ms 8804 KB Output is correct
14 Correct 2 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 102 ms 25460 KB Output is correct
17 Correct 2 ms 5000 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 223 ms 47276 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 3 ms 5204 KB Output is correct
27 Correct 4 ms 5332 KB Output is correct
28 Correct 84 ms 21952 KB Output is correct
29 Correct 127 ms 30268 KB Output is correct
30 Correct 178 ms 38932 KB Output is correct
31 Correct 232 ms 47280 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 2 ms 4948 KB Output is correct
40 Correct 2 ms 4948 KB Output is correct
41 Correct 2 ms 4948 KB Output is correct
42 Correct 2 ms 4948 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5204 KB Output is correct
45 Correct 107 ms 24048 KB Output is correct
46 Correct 162 ms 33220 KB Output is correct
47 Correct 173 ms 33284 KB Output is correct
48 Correct 2 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 2 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 2 ms 4948 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Correct 2 ms 4976 KB Output is correct
55 Correct 238 ms 46920 KB Output is correct
56 Correct 2 ms 4948 KB Output is correct
57 Correct 4 ms 5384 KB Output is correct
58 Correct 7 ms 6304 KB Output is correct
59 Correct 5 ms 5812 KB Output is correct
60 Correct 104 ms 25860 KB Output is correct
61 Correct 169 ms 34380 KB Output is correct
62 Correct 183 ms 39648 KB Output is correct
63 Correct 232 ms 46804 KB Output is correct
64 Correct 2 ms 4948 KB Output is correct
65 Correct 2 ms 4948 KB Output is correct
66 Correct 2 ms 4948 KB Output is correct
67 Correct 218 ms 45964 KB Output is correct
68 Correct 219 ms 47288 KB Output is correct
69 Correct 215 ms 46372 KB Output is correct
70 Correct 3 ms 5332 KB Output is correct
71 Correct 5 ms 5692 KB Output is correct
72 Correct 105 ms 23808 KB Output is correct
73 Correct 163 ms 33652 KB Output is correct
74 Correct 220 ms 42628 KB Output is correct
75 Correct 220 ms 45220 KB Output is correct
76 Correct 219 ms 47284 KB Output is correct
77 Correct 4 ms 5460 KB Output is correct
78 Correct 5 ms 5812 KB Output is correct
79 Correct 103 ms 24068 KB Output is correct
80 Correct 160 ms 34056 KB Output is correct
81 Correct 225 ms 43312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4932 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 105 ms 25416 KB Output is correct
10 Correct 9 ms 7056 KB Output is correct
11 Correct 45 ms 15904 KB Output is correct
12 Correct 14 ms 8024 KB Output is correct
13 Correct 12 ms 8804 KB Output is correct
14 Correct 2 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 102 ms 25460 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 244 ms 41224 KB Output is correct
21 Correct 229 ms 41228 KB Output is correct
22 Correct 244 ms 41268 KB Output is correct
23 Correct 176 ms 35000 KB Output is correct
24 Correct 85 ms 13680 KB Output is correct
25 Correct 92 ms 21264 KB Output is correct
26 Correct 77 ms 21300 KB Output is correct
27 Correct 219 ms 45920 KB Output is correct
28 Correct 215 ms 45860 KB Output is correct
29 Correct 249 ms 36512 KB Output is correct
30 Correct 213 ms 36624 KB Output is correct
31 Correct 3 ms 5040 KB Output is correct
32 Correct 17 ms 7568 KB Output is correct
33 Correct 33 ms 9432 KB Output is correct
34 Correct 242 ms 41216 KB Output is correct
35 Correct 6 ms 5812 KB Output is correct
36 Correct 25 ms 9104 KB Output is correct
37 Correct 45 ms 13152 KB Output is correct
38 Incorrect 80 ms 17124 KB Solution announced impossible, but it is possible.
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4932 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 105 ms 25416 KB Output is correct
10 Correct 9 ms 7056 KB Output is correct
11 Correct 45 ms 15904 KB Output is correct
12 Correct 14 ms 8024 KB Output is correct
13 Correct 12 ms 8804 KB Output is correct
14 Correct 2 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 102 ms 25460 KB Output is correct
17 Correct 227 ms 41860 KB Output is correct
18 Correct 240 ms 41888 KB Output is correct
19 Correct 222 ms 41268 KB Output is correct
20 Correct 216 ms 42124 KB Output is correct
21 Correct 192 ms 37320 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 36 ms 10672 KB Output is correct
24 Correct 10 ms 6580 KB Output is correct
25 Correct 31 ms 11808 KB Output is correct
26 Correct 52 ms 14024 KB Output is correct
27 Incorrect 88 ms 20484 KB Solution announced impossible, but it is possible.
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4932 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 105 ms 25416 KB Output is correct
10 Correct 9 ms 7056 KB Output is correct
11 Correct 45 ms 15904 KB Output is correct
12 Correct 14 ms 8024 KB Output is correct
13 Correct 12 ms 8804 KB Output is correct
14 Correct 2 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 102 ms 25460 KB Output is correct
17 Correct 2 ms 5000 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 223 ms 47276 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 3 ms 5204 KB Output is correct
27 Correct 4 ms 5332 KB Output is correct
28 Correct 84 ms 21952 KB Output is correct
29 Correct 127 ms 30268 KB Output is correct
30 Correct 178 ms 38932 KB Output is correct
31 Correct 232 ms 47280 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 2 ms 4948 KB Output is correct
40 Correct 2 ms 4948 KB Output is correct
41 Correct 2 ms 4948 KB Output is correct
42 Correct 2 ms 4948 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5204 KB Output is correct
45 Correct 107 ms 24048 KB Output is correct
46 Correct 162 ms 33220 KB Output is correct
47 Correct 173 ms 33284 KB Output is correct
48 Correct 2 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 2 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 2 ms 4948 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Correct 2 ms 4976 KB Output is correct
55 Correct 238 ms 46920 KB Output is correct
56 Correct 2 ms 4948 KB Output is correct
57 Correct 4 ms 5384 KB Output is correct
58 Correct 7 ms 6304 KB Output is correct
59 Correct 5 ms 5812 KB Output is correct
60 Correct 104 ms 25860 KB Output is correct
61 Correct 169 ms 34380 KB Output is correct
62 Correct 183 ms 39648 KB Output is correct
63 Correct 232 ms 46804 KB Output is correct
64 Correct 2 ms 4948 KB Output is correct
65 Correct 2 ms 4948 KB Output is correct
66 Correct 2 ms 4948 KB Output is correct
67 Correct 218 ms 45964 KB Output is correct
68 Correct 219 ms 47288 KB Output is correct
69 Correct 215 ms 46372 KB Output is correct
70 Correct 3 ms 5332 KB Output is correct
71 Correct 5 ms 5692 KB Output is correct
72 Correct 105 ms 23808 KB Output is correct
73 Correct 163 ms 33652 KB Output is correct
74 Correct 220 ms 42628 KB Output is correct
75 Correct 220 ms 45220 KB Output is correct
76 Correct 219 ms 47284 KB Output is correct
77 Correct 4 ms 5460 KB Output is correct
78 Correct 5 ms 5812 KB Output is correct
79 Correct 103 ms 24068 KB Output is correct
80 Correct 160 ms 34056 KB Output is correct
81 Correct 225 ms 43312 KB Output is correct
82 Correct 2 ms 4948 KB Output is correct
83 Correct 2 ms 4948 KB Output is correct
84 Correct 2 ms 4948 KB Output is correct
85 Correct 244 ms 41224 KB Output is correct
86 Correct 229 ms 41228 KB Output is correct
87 Correct 244 ms 41268 KB Output is correct
88 Correct 176 ms 35000 KB Output is correct
89 Correct 85 ms 13680 KB Output is correct
90 Correct 92 ms 21264 KB Output is correct
91 Correct 77 ms 21300 KB Output is correct
92 Correct 219 ms 45920 KB Output is correct
93 Correct 215 ms 45860 KB Output is correct
94 Correct 249 ms 36512 KB Output is correct
95 Correct 213 ms 36624 KB Output is correct
96 Correct 3 ms 5040 KB Output is correct
97 Correct 17 ms 7568 KB Output is correct
98 Correct 33 ms 9432 KB Output is correct
99 Correct 242 ms 41216 KB Output is correct
100 Correct 6 ms 5812 KB Output is correct
101 Correct 25 ms 9104 KB Output is correct
102 Correct 45 ms 13152 KB Output is correct
103 Incorrect 80 ms 17124 KB Solution announced impossible, but it is possible.
104 Halted 0 ms 0 KB -