Submission #1039828

# Submission time Handle Problem Language Result Execution time Memory
1039828 2024-07-31T09:58:44 Z vjudge1 Fountain Parks (IOI21_parks) C++17
30 / 100
244 ms 41152 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;

struct dsu {
	vector<int> e;
	int cc;
	dsu(int n) {
		cc=n;
		e=vector<int> (n, -1);
	}
	int get(int a) {
		if(e[a] < 0)return a;
		return e[a] = get(e[a]);
	}
	bool unite(int a, int b) {
		a=get(a), b=get(b);
		if(a==b)return false;
		cc--;
		if(-e[a] > -e[b])swap(a, b);
		e[b]+=e[a];
		e[a]=b;
		return true;
	}
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
	vector<vector<int>> p(7);
	int n = x.size();
	map<pair<int,int>, int> mp;
	for(int i = 0;i<n;i++) {
		mp[{x[i], y[i]}]=i;
		p[x[i]].push_back(i);
	}
	dsu d(n);
	vector<int> u, v;
	for(int i= 0;i<7;i++) {
		sort(p[i].begin(), p[i].end(), [&](int a, int b) {
					return y[a] < y[b];
				});
	}
	{
		int i = 6;
		for(int j = 1;j<(int)p[i].size();j++) {
			if(y[p[i][j]] == y[p[i][j-1]] + 2){
				if(d.unite(p[i][j], p[i][j-1])) {
					v.push_back(p[i][j]);
					u.push_back(p[i][j-1]);
				}
			}
		}
	}
	{
		int i = 2;
		for(int j = 1;j<(int)p[i].size();j++) {
			if(y[p[i][j]] == y[p[i][j-1]] + 2){
				if(d.unite(p[i][j], p[i][j-1])) {
					v.push_back(p[i][j]);
					u.push_back(p[i][j-1]);
				}
			}
		}
	}
	{
		int i = 4;
		for(int j = 1;j<(int)p[i].size();j++) {
			if(y[p[i][j]] == y[p[i][j-1]] + 2){
				if(d.unite(p[i][j], p[i][j-1])) {
					v.push_back(p[i][j]);
					u.push_back(p[i][j-1]);
				}
			}
		}
	}
	{
		for(int j:p[4]) {
			if(mp.find({x[j]-2, y[j]}) != mp.end() and d.unite(j, mp[{x[j]-2, y[j]}])) {
				u.push_back(mp[{x[j]-2, y[j]}]);
				v.push_back(j);
			}
		}
		for(int j:p[4]) {
			if(mp.find({x[j]+2, y[j]}) != mp.end() and d.unite(j, mp[{x[j]+2, y[j]}])) {
				v.push_back(mp[{x[j]+2, y[j]}]);
				u.push_back(j);
			}
		}
	}
//	for(int i = 0;i<(int)v.size();i++) {
//		cout << u[i] << " "<< v[i] << endl;
//	}
	vector<int> a, b;
	if(d.cc != 1)return 0;
	map<pair<int,int>, bool> used;
	for(int j = 0;j<n-1;j++) {
		if(x[u[j]] == x[v[j]]) {
			if(x[u[j]] == 2) {
				a.push_back(x[u[j]]-1);
				b.push_back(y[u[j]]+1);
				used[{x[u[j]]-1,y[u[j]]+1}]=1;
			}
			else if(x[u[j]] == 6) {
				a.push_back(x[u[j]]+1);
				b.push_back(y[u[j]]+1);
				used[{x[u[j]]+1,y[u[j]]+1}]=1;
			}
			else if(x[u[j]] == 4)  {
				a.push_back(-1);
				b.push_back(-1);
			}
		}
		else if(x[u[j]] == 2) {
			a.push_back(x[u[j]]+1);
			int c = 1;
			if(y[u[j]]%4 == 0)c=-1;
			b.push_back(y[u[j]]+c);
			used[{x[u[j]]+1, y[u[j]]+c}]=1;
		} else if(x[u[j]] == 4) {
			a.push_back(x[u[j]]+1);
			int c = 1;
			if(y[u[j]]%4 != 0)c=-1;
			b.push_back(y[u[j]]+c);
			used[{x[u[j]]+1, y[u[j]]+c}]=1;
		}
	}
	for(int j = 0;j<n-1;j++) {
		if(a[j] == -1) {
			if(!used[{x[u[j]]-1, y[u[j]]+1}]) {
				a[j] = x[u[j]]-1;
				b[j] = y[u[j]]+1;
				used[{x[u[j]]-1, y[u[j]]+1}]=1;
			}
			else if(!used[{x[u[j]]+1, y[u[j]]+1}]) {
				a[j] = x[u[j]]+1;
				b[j] = y[u[j]]+1;
				used[{x[u[j]]+1, y[u[j]]+1}]=1;
			}
			else {
				return 0;
			}
		}
	}
	build(u, v, a, b);
	return 1;
}
# Verdict Execution time Memory 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 1 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 83 ms 20120 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 32 ms 10904 KB Output is correct
12 Correct 9 ms 3420 KB Output is correct
13 Correct 12 ms 4740 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 93 ms 19912 KB Output is correct
# Verdict Execution time Memory 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 1 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 83 ms 20120 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 32 ms 10904 KB Output is correct
12 Correct 9 ms 3420 KB Output is correct
13 Correct 12 ms 4740 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 93 ms 19912 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 1 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 220 ms 39468 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 77 ms 15944 KB Output is correct
29 Correct 121 ms 23916 KB Output is correct
30 Correct 172 ms 31548 KB Output is correct
31 Correct 216 ms 39552 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 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 1 ms 348 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 99 ms 19848 KB Output is correct
46 Correct 151 ms 28768 KB Output is correct
47 Correct 151 ms 28736 KB Output is correct
# Verdict Execution time Memory 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 1 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 83 ms 20120 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 32 ms 10904 KB Output is correct
12 Correct 9 ms 3420 KB Output is correct
13 Correct 12 ms 4740 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 93 ms 19912 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 1 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 220 ms 39468 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 77 ms 15944 KB Output is correct
29 Correct 121 ms 23916 KB Output is correct
30 Correct 172 ms 31548 KB Output is correct
31 Correct 216 ms 39552 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 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 1 ms 348 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 99 ms 19848 KB Output is correct
46 Correct 151 ms 28768 KB Output is correct
47 Correct 151 ms 28736 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 225 ms 41148 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 2 ms 600 KB Output is correct
58 Correct 5 ms 1728 KB Output is correct
59 Correct 5 ms 1372 KB Output is correct
60 Correct 102 ms 20680 KB Output is correct
61 Correct 146 ms 27856 KB Output is correct
62 Correct 182 ms 34036 KB Output is correct
63 Correct 233 ms 41040 KB Output is correct
64 Correct 1 ms 436 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 217 ms 41012 KB Output is correct
68 Correct 201 ms 41036 KB Output is correct
69 Correct 205 ms 40836 KB Output is correct
70 Correct 2 ms 856 KB Output is correct
71 Correct 6 ms 1116 KB Output is correct
72 Correct 122 ms 20720 KB Output is correct
73 Correct 208 ms 31036 KB Output is correct
74 Correct 235 ms 41152 KB Output is correct
75 Correct 244 ms 41108 KB Output is correct
76 Correct 215 ms 41024 KB Output is correct
77 Correct 3 ms 856 KB Output is correct
78 Correct 6 ms 1372 KB Output is correct
79 Correct 106 ms 20716 KB Output is correct
80 Correct 179 ms 31052 KB Output is correct
81 Correct 223 ms 41148 KB Output is correct
# Verdict Execution time Memory 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 1 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 83 ms 20120 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 32 ms 10904 KB Output is correct
12 Correct 9 ms 3420 KB Output is correct
13 Correct 12 ms 4740 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 93 ms 19912 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 1 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 83 ms 20120 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 32 ms 10904 KB Output is correct
12 Correct 9 ms 3420 KB Output is correct
13 Correct 12 ms 4740 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 93 ms 19912 KB Output is correct
17 Runtime error 25 ms 6880 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 1 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 83 ms 20120 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 32 ms 10904 KB Output is correct
12 Correct 9 ms 3420 KB Output is correct
13 Correct 12 ms 4740 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 93 ms 19912 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 1 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 220 ms 39468 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 77 ms 15944 KB Output is correct
29 Correct 121 ms 23916 KB Output is correct
30 Correct 172 ms 31548 KB Output is correct
31 Correct 216 ms 39552 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 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 1 ms 348 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 99 ms 19848 KB Output is correct
46 Correct 151 ms 28768 KB Output is correct
47 Correct 151 ms 28736 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 225 ms 41148 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 2 ms 600 KB Output is correct
58 Correct 5 ms 1728 KB Output is correct
59 Correct 5 ms 1372 KB Output is correct
60 Correct 102 ms 20680 KB Output is correct
61 Correct 146 ms 27856 KB Output is correct
62 Correct 182 ms 34036 KB Output is correct
63 Correct 233 ms 41040 KB Output is correct
64 Correct 1 ms 436 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 217 ms 41012 KB Output is correct
68 Correct 201 ms 41036 KB Output is correct
69 Correct 205 ms 40836 KB Output is correct
70 Correct 2 ms 856 KB Output is correct
71 Correct 6 ms 1116 KB Output is correct
72 Correct 122 ms 20720 KB Output is correct
73 Correct 208 ms 31036 KB Output is correct
74 Correct 235 ms 41152 KB Output is correct
75 Correct 244 ms 41108 KB Output is correct
76 Correct 215 ms 41024 KB Output is correct
77 Correct 3 ms 856 KB Output is correct
78 Correct 6 ms 1372 KB Output is correct
79 Correct 106 ms 20716 KB Output is correct
80 Correct 179 ms 31052 KB Output is correct
81 Correct 223 ms 41148 KB Output is correct
82 Runtime error 1 ms 348 KB Execution killed with signal 11
83 Halted 0 ms 0 KB -