Submission #570492

# Submission time Handle Problem Language Result Execution time Memory
570492 2022-05-30T08:39:05 Z 8e7 Fountain Parks (IOI21_parks) C++17
30 / 100
284 ms 67056 KB
//Challenge: Accepted
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 200005
#define pii pair<ll, ll>
#define ff first
#define ss second
vector<pii> xv[maxn], yv[maxn];
unordered_map<ll, vector<pii> > adj;
unordered_map<ll, bool> vis;
ll h(int x, int y) {
	return (ll)x * maxn + y;
}


struct DSU{
	int par[maxn];
	int merges = 0;
	void init(int n) {
		for (int i = 0;i < n;i++) par[i] = i;
	}
	int find(int a) {
		return a == par[a] ? a : (par[a] = find(par[a]));
	}
	void Union(int a, int b) {
		a = find(a), b = find(b);
		if (a == b) return;
		merges++;
		par[a] = b;
	}
} dsu;
vector<int> u, v, a, b;
void dfs(ll n, ll prv) {
	vis[n] = 1;
	for (auto p:adj[n]) {
		if (p.ff != prv) {
			u.push_back(p.ss / maxn);
			v.push_back(p.ss % maxn);
			a.push_back(n / maxn);
			b.push_back(n % maxn);
			if (!vis[p.ff]) dfs(p.ff, n);
		}
	}
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
	int n = x.size();
	dsu.init(n);
	for (int i = 0;i < n;i++) {
		xv[x[i]].push_back({y[i], i});
		yv[y[i]].push_back({x[i], i});
	}

	for (int i = 0;i < maxn;i += 2) {
		sort(xv[i].begin(), xv[i].end());
		sort(yv[i].begin(), yv[i].end());
		for (int j = 0;j < (int)xv[i].size() - 1;j++) {
			if (i == 4) continue;
			if (xv[i][j].ff + 2 == xv[i][j+1].ff) {
				dsu.Union(xv[i][j].ss, xv[i][j+1].ss);
				u.push_back(xv[i][j].ss);
				v.push_back(xv[i][j+1].ss);
				b.push_back(xv[i][j].ff + 1);
				if (i == 2) a.push_back(1);
				else a.push_back(7);
			}
		}
		for (int j = 0;j < (int)yv[i].size() - 1;j++) {
			if (yv[i][j].ff + 2 == yv[i][j+1].ff) {
				dsu.Union(yv[i][j].ss, yv[i][j+1].ss);
				ll ind = h(yv[i][j].ss, yv[i][j+1].ss), v1 = h(yv[i][j].ff + 1, i-1), v2 = h(yv[i][j].ff + 1, i+1);
				adj[v1].push_back({v2, ind});
				adj[v2].push_back({v1, ind});
			}
		}
	}
	{
		int i = 4;
		for (int j = 0;j < (int)xv[i].size() - 1;j++) {
			if (xv[i][j].ff + 2 == xv[i][j+1].ff) {
				if (dsu.find(xv[i][j].ss) == dsu.find(xv[i][j+1].ss)) continue;
				dsu.Union(xv[i][j].ss, xv[i][j+1].ss);
				ll ind = h(xv[i][j].ss, xv[i][j+1].ss), v1 = h(i-1, xv[i][j].ff + 1), v2 = h(i+1, xv[i][j].ff + 1);
				adj[v1].push_back({v2, ind});
				adj[v2].push_back({v1, ind});
			}
		}
	}
	if (dsu.merges != n - 1) return 0;
	for (auto i:adj) {
		if (i.ss.size() == 1 && !vis[i.ff]) dfs(i.ff, -1);
	}
	for (auto i:adj) {
		if (!vis[i.ff]) dfs(i.ff, i.ss[0].ff);
	}
	build(u, v, a, b);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 7 ms 9684 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 77 ms 22612 KB Output is correct
10 Correct 11 ms 11052 KB Output is correct
11 Correct 38 ms 16520 KB Output is correct
12 Correct 14 ms 11640 KB Output is correct
13 Correct 18 ms 13888 KB Output is correct
14 Correct 6 ms 9700 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 77 ms 22588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 7 ms 9684 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 77 ms 22612 KB Output is correct
10 Correct 11 ms 11052 KB Output is correct
11 Correct 38 ms 16520 KB Output is correct
12 Correct 14 ms 11640 KB Output is correct
13 Correct 18 ms 13888 KB Output is correct
14 Correct 6 ms 9700 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 77 ms 22588 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9696 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 7 ms 9684 KB Output is correct
21 Correct 7 ms 9684 KB Output is correct
22 Correct 7 ms 9684 KB Output is correct
23 Correct 220 ms 61872 KB Output is correct
24 Correct 6 ms 9684 KB Output is correct
25 Correct 9 ms 9940 KB Output is correct
26 Correct 7 ms 10068 KB Output is correct
27 Correct 7 ms 10092 KB Output is correct
28 Correct 81 ms 30064 KB Output is correct
29 Correct 116 ms 40500 KB Output is correct
30 Correct 160 ms 50984 KB Output is correct
31 Correct 214 ms 61872 KB Output is correct
32 Correct 7 ms 9700 KB Output is correct
33 Correct 6 ms 9700 KB Output is correct
34 Correct 6 ms 9592 KB Output is correct
35 Correct 7 ms 9684 KB Output is correct
36 Correct 6 ms 9684 KB Output is correct
37 Correct 7 ms 9684 KB Output is correct
38 Correct 6 ms 9684 KB Output is correct
39 Correct 6 ms 9684 KB Output is correct
40 Correct 6 ms 9684 KB Output is correct
41 Correct 6 ms 9684 KB Output is correct
42 Correct 6 ms 9684 KB Output is correct
43 Correct 8 ms 10020 KB Output is correct
44 Correct 8 ms 10196 KB Output is correct
45 Correct 120 ms 37084 KB Output is correct
46 Correct 184 ms 48700 KB Output is correct
47 Correct 181 ms 48728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 7 ms 9684 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 77 ms 22612 KB Output is correct
10 Correct 11 ms 11052 KB Output is correct
11 Correct 38 ms 16520 KB Output is correct
12 Correct 14 ms 11640 KB Output is correct
13 Correct 18 ms 13888 KB Output is correct
14 Correct 6 ms 9700 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 77 ms 22588 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9696 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 7 ms 9684 KB Output is correct
21 Correct 7 ms 9684 KB Output is correct
22 Correct 7 ms 9684 KB Output is correct
23 Correct 220 ms 61872 KB Output is correct
24 Correct 6 ms 9684 KB Output is correct
25 Correct 9 ms 9940 KB Output is correct
26 Correct 7 ms 10068 KB Output is correct
27 Correct 7 ms 10092 KB Output is correct
28 Correct 81 ms 30064 KB Output is correct
29 Correct 116 ms 40500 KB Output is correct
30 Correct 160 ms 50984 KB Output is correct
31 Correct 214 ms 61872 KB Output is correct
32 Correct 7 ms 9700 KB Output is correct
33 Correct 6 ms 9700 KB Output is correct
34 Correct 6 ms 9592 KB Output is correct
35 Correct 7 ms 9684 KB Output is correct
36 Correct 6 ms 9684 KB Output is correct
37 Correct 7 ms 9684 KB Output is correct
38 Correct 6 ms 9684 KB Output is correct
39 Correct 6 ms 9684 KB Output is correct
40 Correct 6 ms 9684 KB Output is correct
41 Correct 6 ms 9684 KB Output is correct
42 Correct 6 ms 9684 KB Output is correct
43 Correct 8 ms 10020 KB Output is correct
44 Correct 8 ms 10196 KB Output is correct
45 Correct 120 ms 37084 KB Output is correct
46 Correct 184 ms 48700 KB Output is correct
47 Correct 181 ms 48728 KB Output is correct
48 Correct 6 ms 9684 KB Output is correct
49 Correct 6 ms 9596 KB Output is correct
50 Correct 6 ms 9684 KB Output is correct
51 Correct 6 ms 9684 KB Output is correct
52 Correct 7 ms 9688 KB Output is correct
53 Correct 6 ms 9696 KB Output is correct
54 Correct 7 ms 9700 KB Output is correct
55 Correct 259 ms 66792 KB Output is correct
56 Correct 6 ms 9704 KB Output is correct
57 Correct 9 ms 10324 KB Output is correct
58 Correct 13 ms 11440 KB Output is correct
59 Correct 11 ms 11248 KB Output is correct
60 Correct 115 ms 38040 KB Output is correct
61 Correct 171 ms 47424 KB Output is correct
62 Correct 212 ms 54376 KB Output is correct
63 Correct 260 ms 67056 KB Output is correct
64 Correct 6 ms 9684 KB Output is correct
65 Correct 6 ms 9696 KB Output is correct
66 Correct 6 ms 9684 KB Output is correct
67 Correct 162 ms 36432 KB Output is correct
68 Correct 165 ms 38064 KB Output is correct
69 Correct 172 ms 37088 KB Output is correct
70 Correct 9 ms 10324 KB Output is correct
71 Correct 11 ms 10864 KB Output is correct
72 Correct 115 ms 32356 KB Output is correct
73 Correct 214 ms 45464 KB Output is correct
74 Correct 284 ms 55472 KB Output is correct
75 Correct 234 ms 59904 KB Output is correct
76 Correct 163 ms 38060 KB Output is correct
77 Correct 8 ms 10452 KB Output is correct
78 Correct 10 ms 11124 KB Output is correct
79 Correct 125 ms 33820 KB Output is correct
80 Correct 202 ms 46868 KB Output is correct
81 Correct 268 ms 58416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 7 ms 9684 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 77 ms 22612 KB Output is correct
10 Correct 11 ms 11052 KB Output is correct
11 Correct 38 ms 16520 KB Output is correct
12 Correct 14 ms 11640 KB Output is correct
13 Correct 18 ms 13888 KB Output is correct
14 Correct 6 ms 9700 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 77 ms 22588 KB Output is correct
17 Incorrect 6 ms 9684 KB Tree (a[0], b[0]) = (7, 3) is not adjacent to edge between u[0]=0 @(200000, 2) and v[0]=1 @(200000, 4)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 7 ms 9684 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 77 ms 22612 KB Output is correct
10 Correct 11 ms 11052 KB Output is correct
11 Correct 38 ms 16520 KB Output is correct
12 Correct 14 ms 11640 KB Output is correct
13 Correct 18 ms 13888 KB Output is correct
14 Correct 6 ms 9700 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 77 ms 22588 KB Output is correct
17 Incorrect 283 ms 63684 KB Tree (a[50000], b[50000]) = (7, 3) is not adjacent to edge between u[50000]=138413 @(100002, 2) and v[50000]=87394 @(100002, 4)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 7 ms 9684 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 77 ms 22612 KB Output is correct
10 Correct 11 ms 11052 KB Output is correct
11 Correct 38 ms 16520 KB Output is correct
12 Correct 14 ms 11640 KB Output is correct
13 Correct 18 ms 13888 KB Output is correct
14 Correct 6 ms 9700 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 77 ms 22588 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9696 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 7 ms 9684 KB Output is correct
21 Correct 7 ms 9684 KB Output is correct
22 Correct 7 ms 9684 KB Output is correct
23 Correct 220 ms 61872 KB Output is correct
24 Correct 6 ms 9684 KB Output is correct
25 Correct 9 ms 9940 KB Output is correct
26 Correct 7 ms 10068 KB Output is correct
27 Correct 7 ms 10092 KB Output is correct
28 Correct 81 ms 30064 KB Output is correct
29 Correct 116 ms 40500 KB Output is correct
30 Correct 160 ms 50984 KB Output is correct
31 Correct 214 ms 61872 KB Output is correct
32 Correct 7 ms 9700 KB Output is correct
33 Correct 6 ms 9700 KB Output is correct
34 Correct 6 ms 9592 KB Output is correct
35 Correct 7 ms 9684 KB Output is correct
36 Correct 6 ms 9684 KB Output is correct
37 Correct 7 ms 9684 KB Output is correct
38 Correct 6 ms 9684 KB Output is correct
39 Correct 6 ms 9684 KB Output is correct
40 Correct 6 ms 9684 KB Output is correct
41 Correct 6 ms 9684 KB Output is correct
42 Correct 6 ms 9684 KB Output is correct
43 Correct 8 ms 10020 KB Output is correct
44 Correct 8 ms 10196 KB Output is correct
45 Correct 120 ms 37084 KB Output is correct
46 Correct 184 ms 48700 KB Output is correct
47 Correct 181 ms 48728 KB Output is correct
48 Correct 6 ms 9684 KB Output is correct
49 Correct 6 ms 9596 KB Output is correct
50 Correct 6 ms 9684 KB Output is correct
51 Correct 6 ms 9684 KB Output is correct
52 Correct 7 ms 9688 KB Output is correct
53 Correct 6 ms 9696 KB Output is correct
54 Correct 7 ms 9700 KB Output is correct
55 Correct 259 ms 66792 KB Output is correct
56 Correct 6 ms 9704 KB Output is correct
57 Correct 9 ms 10324 KB Output is correct
58 Correct 13 ms 11440 KB Output is correct
59 Correct 11 ms 11248 KB Output is correct
60 Correct 115 ms 38040 KB Output is correct
61 Correct 171 ms 47424 KB Output is correct
62 Correct 212 ms 54376 KB Output is correct
63 Correct 260 ms 67056 KB Output is correct
64 Correct 6 ms 9684 KB Output is correct
65 Correct 6 ms 9696 KB Output is correct
66 Correct 6 ms 9684 KB Output is correct
67 Correct 162 ms 36432 KB Output is correct
68 Correct 165 ms 38064 KB Output is correct
69 Correct 172 ms 37088 KB Output is correct
70 Correct 9 ms 10324 KB Output is correct
71 Correct 11 ms 10864 KB Output is correct
72 Correct 115 ms 32356 KB Output is correct
73 Correct 214 ms 45464 KB Output is correct
74 Correct 284 ms 55472 KB Output is correct
75 Correct 234 ms 59904 KB Output is correct
76 Correct 163 ms 38060 KB Output is correct
77 Correct 8 ms 10452 KB Output is correct
78 Correct 10 ms 11124 KB Output is correct
79 Correct 125 ms 33820 KB Output is correct
80 Correct 202 ms 46868 KB Output is correct
81 Correct 268 ms 58416 KB Output is correct
82 Incorrect 6 ms 9684 KB Tree (a[0], b[0]) = (7, 3) is not adjacent to edge between u[0]=0 @(200000, 2) and v[0]=1 @(200000, 4)
83 Halted 0 ms 0 KB -