Submission #831544

# Submission time Handle Problem Language Result Execution time Memory
831544 2023-08-20T10:18:42 Z andrey27_sm Fountain Parks (IOI21_parks) C++17
15 / 100
123 ms 23208 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;
int construct_roads(vector<int> x, vector<int> y) {
	int n = x.size();
	int l = 1e9;
	int r = 0;
	for (int i = 0; i < n; ++i)
	{
		cons[y[i]/2].push_back({x[i],i});
		mask_l[y[i]/2]|=(1<<(x[i]/2-1));
	}
	for (int i = 0; i <= 100000; ++i)
	{
		if(mask_l[i]){
			l = min(l,i);
			r = max(r,i);
			sort(cons[i].begin(), cons[i].end());
		}
	}
	for (int i = l; i <= r; ++i)
	{
		if(i != l and (mask_l[i]&mask_l[i-1]) == 0) return 0;
	}
	int p = l+1;
	bool con = 1;
	if(mask_l[l] != 5)
	{
		for(int i = 0;i+1 < cons[l].size();i++){
			u.push_back(cons[l][i].second);
			v.push_back(cons[l][i+1].second);
			a.push_back(cons[l][i].first+1);
			b.push_back(2*l-1);
		}
	}
	else{
		con = 0;
	}
	while(p <= r){
		if(mask_l[p] == 5 and (mask_l[p-1]&mask_l[p]) != 5) con = 0;
		if(con == 0){
			if(mask_l[p] == 5){
				for(auto e:cons[p-1]){
					if(e.first == 2){
						u.push_back(e.second);
						v.push_back(cons[p][0].second);
						a.push_back(e.first-1);
						b.push_back(2*p-1);
					}
					if(e.first == 6){
						u.push_back(e.second);
						v.push_back(cons[p][1].second);
						a.push_back(e.first+1);
						b.push_back(2*p-1);
					}
				}
			}
			else if(mask_l[p] == 7){
				for(auto e:cons[p-1]){
					if(e.first == 2){
						u.push_back(e.second);
						v.push_back(cons[p][0].second);
						a.push_back(e.first-1);
						b.push_back(2*p-1);
					}
					if(e.first == 6){
						u.push_back(e.second);
						v.push_back(cons[p][1].second);
						a.push_back(e.first+1);
						b.push_back(2*p-1);
					}
				}
				u.push_back(cons[p][0].second);
				v.push_back(cons[p][1].second);
				a.push_back(cons[p][1].first-1);
				b.push_back(2*p-1);


				u.push_back(cons[p][1].second);
				v.push_back(cons[p][2].second);
				a.push_back(cons[p][2].first-1);
				b.push_back(2*p-1);	
				con = 1;
			}
			else return 0;
		}
		else if(mask_l[p] == 7 and mask_l[p-1] == 2){
			u.push_back(cons[p][0].second);
			v.push_back(cons[p][1].second);
			a.push_back(cons[p][1].first-1);
			b.push_back(2*p-1);


			u.push_back(cons[p][1].second);
			v.push_back(cons[p][2].second);
			a.push_back(cons[p][2].first-1);
			b.push_back(2*p+1);	

			u.push_back(cons[p-1][0].second);
			v.push_back(cons[p][1].second);
			a.push_back(cons[p][1].first+1);
			b.push_back(2*p-1);
		}
		else if(mask_l[p-1] == 7){
			for(auto e:cons[p]){
				if(e.first == 2 or e.first == 4){
					u.push_back(e.second);
					v.push_back(cons[p-1][e.first/2-1].second);
					a.push_back(e.first-1);
					b.push_back(2*p-1);
				}
				else{
					u.push_back(e.second);
					v.push_back(cons[p-1][e.first/2-1].second);
					a.push_back(e.first+1);
					b.push_back(2*p-1);
				}
			}
		}
		else{
			int mask_blocked = 0;
			if((mask_l[p]&3) == 3 and (mask_l[p-1]&3) != 3){
				u.push_back(cons[p][0].second);
				v.push_back(cons[p][1].second);
				a.push_back(cons[p][1].first-1);
				b.push_back(2*p-1);
				mask_blocked|=1;
			}
			if(((mask_l[p]>>1)&3) == 3 and ((mask_l[p-1]>>1)&3) != 3){
				u.push_back(cons[p][0+(mask_l[p]&1)].second);
				v.push_back(cons[p][1+(mask_l[p]&1)].second);
				a.push_back(cons[p][1+(mask_l[p]&1)].first-1);
				b.push_back(2*p-1);
				mask_blocked|=2;
			}
			for(auto e:cons[p]){
				for(auto E:cons[p-1]){
					if(e.first != E.first) continue;
					//cout << e.second << " " << E.second << "--\n";
					u.push_back(e.second);
					v.push_back(E.second);
					b.push_back(2*p-1);
					if(e.first == 2) a.push_back(1);
					else if(e.first == 6) a.push_back(7);
					else if(mask_blocked&1){
						a.push_back(5);
					}
					else{
						a.push_back(3);
					}
				}
			}
		}
		p++;
	}
	if(con == 0) 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:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int i = 0;i+1 < cons[l].size();i++){
      |                 ~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 5004 KB Output is correct
9 Correct 49 ms 15704 KB Output is correct
10 Correct 8 ms 6296 KB Output is correct
11 Correct 26 ms 10804 KB Output is correct
12 Correct 13 ms 6868 KB Output is correct
13 Correct 10 ms 7636 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5036 KB Output is correct
16 Correct 50 ms 15728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 5004 KB Output is correct
9 Correct 49 ms 15704 KB Output is correct
10 Correct 8 ms 6296 KB Output is correct
11 Correct 26 ms 10804 KB Output is correct
12 Correct 13 ms 6868 KB Output is correct
13 Correct 10 ms 7636 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5036 KB Output is correct
16 Correct 50 ms 15728 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 5008 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 121 ms 22764 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 5140 KB Output is correct
26 Correct 3 ms 5016 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 39 ms 12136 KB Output is correct
29 Correct 59 ms 15768 KB Output is correct
30 Correct 78 ms 19372 KB Output is correct
31 Correct 104 ms 22820 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 3 ms 5008 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 5076 KB Output is correct
45 Correct 49 ms 14632 KB Output is correct
46 Correct 71 ms 18888 KB Output is correct
47 Correct 74 ms 19256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 5004 KB Output is correct
9 Correct 49 ms 15704 KB Output is correct
10 Correct 8 ms 6296 KB Output is correct
11 Correct 26 ms 10804 KB Output is correct
12 Correct 13 ms 6868 KB Output is correct
13 Correct 10 ms 7636 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5036 KB Output is correct
16 Correct 50 ms 15728 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 5008 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 121 ms 22764 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 5140 KB Output is correct
26 Correct 3 ms 5016 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 39 ms 12136 KB Output is correct
29 Correct 59 ms 15768 KB Output is correct
30 Correct 78 ms 19372 KB Output is correct
31 Correct 104 ms 22820 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 3 ms 5008 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 5076 KB Output is correct
45 Correct 49 ms 14632 KB Output is correct
46 Correct 71 ms 18888 KB Output is correct
47 Correct 74 ms 19256 KB Output is correct
48 Correct 2 ms 4948 KB Output is correct
49 Correct 2 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 2 ms 5000 KB Output is correct
52 Correct 2 ms 4948 KB Output is correct
53 Correct 2 ms 5008 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 102 ms 23208 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 4 ms 5144 KB Output is correct
58 Correct 5 ms 5656 KB Output is correct
59 Correct 5 ms 5416 KB Output is correct
60 Correct 47 ms 14004 KB Output is correct
61 Correct 74 ms 17188 KB Output is correct
62 Correct 81 ms 20136 KB Output is correct
63 Correct 123 ms 23152 KB Output is correct
64 Correct 2 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 ms 4948 KB Output is correct
67 Incorrect 96 ms 22768 KB Pair u[199995]=165610 @(6, 199998) and v[199995]=112913 @(4, 200000) does not form a valid edge (distance != 2)
68 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 5004 KB Output is correct
9 Correct 49 ms 15704 KB Output is correct
10 Correct 8 ms 6296 KB Output is correct
11 Correct 26 ms 10804 KB Output is correct
12 Correct 13 ms 6868 KB Output is correct
13 Correct 10 ms 7636 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5036 KB Output is correct
16 Correct 50 ms 15728 KB Output is correct
17 Incorrect 3 ms 4948 KB Tree (a[1], b[1]) = (3, 3) is not adjacent to edge between u[1]=1 @(200000, 4) and v[1]=0 @(200000, 2)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 5004 KB Output is correct
9 Correct 49 ms 15704 KB Output is correct
10 Correct 8 ms 6296 KB Output is correct
11 Correct 26 ms 10804 KB Output is correct
12 Correct 13 ms 6868 KB Output is correct
13 Correct 10 ms 7636 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5036 KB Output is correct
16 Correct 50 ms 15728 KB Output is correct
17 Incorrect 86 ms 19848 KB Tree (a[50001], b[50001]) = (3, 3) is not adjacent to edge between u[50001]=87394 @(100002, 4) and v[50001]=138413 @(100002, 2)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 5004 KB Output is correct
9 Correct 49 ms 15704 KB Output is correct
10 Correct 8 ms 6296 KB Output is correct
11 Correct 26 ms 10804 KB Output is correct
12 Correct 13 ms 6868 KB Output is correct
13 Correct 10 ms 7636 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5036 KB Output is correct
16 Correct 50 ms 15728 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 5008 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 121 ms 22764 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 5140 KB Output is correct
26 Correct 3 ms 5016 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 39 ms 12136 KB Output is correct
29 Correct 59 ms 15768 KB Output is correct
30 Correct 78 ms 19372 KB Output is correct
31 Correct 104 ms 22820 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 3 ms 5008 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 5076 KB Output is correct
45 Correct 49 ms 14632 KB Output is correct
46 Correct 71 ms 18888 KB Output is correct
47 Correct 74 ms 19256 KB Output is correct
48 Correct 2 ms 4948 KB Output is correct
49 Correct 2 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 2 ms 5000 KB Output is correct
52 Correct 2 ms 4948 KB Output is correct
53 Correct 2 ms 5008 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 102 ms 23208 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 4 ms 5144 KB Output is correct
58 Correct 5 ms 5656 KB Output is correct
59 Correct 5 ms 5416 KB Output is correct
60 Correct 47 ms 14004 KB Output is correct
61 Correct 74 ms 17188 KB Output is correct
62 Correct 81 ms 20136 KB Output is correct
63 Correct 123 ms 23152 KB Output is correct
64 Correct 2 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 ms 4948 KB Output is correct
67 Incorrect 96 ms 22768 KB Pair u[199995]=165610 @(6, 199998) and v[199995]=112913 @(4, 200000) does not form a valid edge (distance != 2)
68 Halted 0 ms 0 KB -