Submission #1059631

# Submission time Handle Problem Language Result Execution time Memory
1059631 2024-08-15T06:30:07 Z Gromp15 Fountain Parks (IOI21_parks) C++17
30 / 100
1753 ms 93264 KB
#include <bits/stdc++.h>
#include "parks.h"
#define ar array
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

struct dsu {
	vector<int> p, size;
	dsu(int n) : p(n), size(n, 1) {
		iota(all(p), 0);
	}
	int get(int v) {
		return v == p[v] ? v : p[v] = get(p[v]);
	}
	bool merge(int a, int b) {
		a = get(a), b = get(b);
		if (a == b) return 0;
		if (size[a] < size[b]) swap(a, b);
		size[a] += size[b], p[b] = a;
		return 1;
	}
};

int construct_roads(std::vector<int> x, std::vector<int> y) {
	int n = sz(x);
	map<ar<int, 4>, int> mp;
	map<ar<int, 2>, int> idx;
	for (int i = 0; i < n; i++) idx[{x[i], y[i]}] = i;
	map<ar<int, 2>, int> adj;
	for (int i = 0; i < n; i++) {
		if (idx.count({x[i] + 2, y[i]})) {
			mp[{x[i], y[i], x[i] + 2, y[i]}] += 2;
			adj[{x[i] + 1, y[i] + 1}]++;
			adj[{x[i] + 1, y[i] - 1}]++;
		}
		if (idx.count({x[i], y[i] + 2})) {
			mp[{x[i], y[i], x[i], y[i] + 2}] += 2;
			adj[{x[i] + 1, y[i] + 1}]++;
			adj[{x[i] - 1, y[i] + 1}]++;
		}
	}
	set<pair<int, ar<int, 2>>> q;
	for (auto [x, y] : adj) q.insert({y, x});
	dsu D(n);
	vector<int> a(n-1), b(n-1), c(n-1), d(n-1);
	set<ar<int, 2>> used;
	int now = 0;
	while (q.size()) {
		auto [val, p] = *q.begin();
		q.erase(q.begin());
		if (val != adj[p]) {
			if (adj[p]) {
				q.insert({adj[p], p});
				continue;
			}
		}
		ar<int, 4> seg2{p[0] - 1, p[1] - 1, p[0] - 1, p[1] + 1};
		ar<int, 4> seg3{p[0] + 1, p[1] - 1, p[0] + 1, p[1] + 1};
		ar<int, 4> seg4{p[0] - 1, p[1] - 1, p[0] + 1, p[1] - 1};
		ar<int, 4> seg5{p[0] - 1, p[1] + 1, p[0] + 1, p[1] + 1};
		bool F = 0;
		for (int tp = 0; tp <= 4; tp++) {
			for (auto& seg : {seg2, seg3, seg4, seg5}) if (mp.count(seg) && mp[seg] == tp) {
				int i1 = idx[{seg[0], seg[1]}], i2 = idx[{seg[2], seg[3]}];
				if (D.get(i1) == D.get(i2)) continue;
				F = 1;
				D.merge(i1, i2);
				a[now] = i1, b[now] = i2;
				c[now] = p[0], d[now] = p[1];
				now++;
				ar<int, 2> pt, pt2;
				if (seg[0] != seg[2]) {
					pt = {seg[0] + 1, seg[1] - 1};
					pt2 = {seg[0] + 1, seg[1] + 1};
				}
				else {
					pt = {seg[0] - 1, seg[1] + 1};
					pt2 = {seg[0] + 1, seg[1] + 1};
				}
				for (auto p : {pt, pt2}) adj[p]--;
				break;
			}
			if (F) break;
		}
		if (F) for (auto& seg : {seg2, seg3, seg4, seg5}) mp[seg]--;
	}
	if (D.size[D.get(0)] != n) return 0;
	build(a, b, c, d);
	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 424 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 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 752 ms 48984 KB Output is correct
10 Correct 48 ms 5212 KB Output is correct
11 Correct 368 ms 26560 KB Output is correct
12 Correct 75 ms 7516 KB Output is correct
13 Correct 268 ms 21840 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1340 KB Output is correct
16 Correct 745 ms 48776 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 424 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 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 752 ms 48984 KB Output is correct
10 Correct 48 ms 5212 KB Output is correct
11 Correct 368 ms 26560 KB Output is correct
12 Correct 75 ms 7516 KB Output is correct
13 Correct 268 ms 21840 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1340 KB Output is correct
16 Correct 745 ms 48776 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 0 ms 348 KB Output is correct
21 Correct 1 ms 436 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1717 ms 92104 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 5 ms 860 KB Output is correct
26 Correct 13 ms 1788 KB Output is correct
27 Correct 17 ms 2140 KB Output is correct
28 Correct 524 ms 36836 KB Output is correct
29 Correct 899 ms 55252 KB Output is correct
30 Correct 1322 ms 73648 KB Output is correct
31 Correct 1753 ms 91952 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 344 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 1 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 7 ms 1200 KB Output is correct
44 Correct 11 ms 1372 KB Output is correct
45 Correct 610 ms 43228 KB Output is correct
46 Correct 966 ms 62036 KB Output is correct
47 Correct 923 ms 62112 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 424 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 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 752 ms 48984 KB Output is correct
10 Correct 48 ms 5212 KB Output is correct
11 Correct 368 ms 26560 KB Output is correct
12 Correct 75 ms 7516 KB Output is correct
13 Correct 268 ms 21840 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1340 KB Output is correct
16 Correct 745 ms 48776 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 0 ms 348 KB Output is correct
21 Correct 1 ms 436 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1717 ms 92104 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 5 ms 860 KB Output is correct
26 Correct 13 ms 1788 KB Output is correct
27 Correct 17 ms 2140 KB Output is correct
28 Correct 524 ms 36836 KB Output is correct
29 Correct 899 ms 55252 KB Output is correct
30 Correct 1322 ms 73648 KB Output is correct
31 Correct 1753 ms 91952 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 344 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 1 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 7 ms 1200 KB Output is correct
44 Correct 11 ms 1372 KB Output is correct
45 Correct 610 ms 43228 KB Output is correct
46 Correct 966 ms 62036 KB Output is correct
47 Correct 923 ms 62112 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 432 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1601 ms 84904 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 7 ms 1116 KB Output is correct
58 Correct 25 ms 2900 KB Output is correct
59 Correct 44 ms 4444 KB Output is correct
60 Correct 682 ms 42568 KB Output is correct
61 Correct 987 ms 57428 KB Output is correct
62 Correct 1271 ms 70224 KB Output is correct
63 Correct 1583 ms 85072 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 1645 ms 92100 KB Output is correct
68 Correct 1616 ms 91972 KB Output is correct
69 Correct 1490 ms 91476 KB Output is correct
70 Correct 14 ms 1884 KB Output is correct
71 Correct 31 ms 3420 KB Output is correct
72 Correct 587 ms 41976 KB Output is correct
73 Correct 986 ms 63056 KB Output is correct
74 Correct 1421 ms 83796 KB Output is correct
75 Correct 1595 ms 88896 KB Output is correct
76 Correct 1595 ms 91984 KB Output is correct
77 Correct 24 ms 2396 KB Output is correct
78 Correct 38 ms 3928 KB Output is correct
79 Correct 633 ms 44012 KB Output is correct
80 Correct 1054 ms 66128 KB Output is correct
81 Correct 1498 ms 87892 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 424 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 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 752 ms 48984 KB Output is correct
10 Correct 48 ms 5212 KB Output is correct
11 Correct 368 ms 26560 KB Output is correct
12 Correct 75 ms 7516 KB Output is correct
13 Correct 268 ms 21840 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1340 KB Output is correct
16 Correct 745 ms 48776 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 909 ms 79500 KB Output is correct
21 Correct 1068 ms 79304 KB Output is correct
22 Correct 907 ms 79440 KB Output is correct
23 Correct 1169 ms 78540 KB Output is correct
24 Correct 183 ms 22356 KB Output is correct
25 Correct 1383 ms 85064 KB Output is correct
26 Correct 1357 ms 85060 KB Output is correct
27 Correct 1418 ms 91220 KB Output is correct
28 Correct 1399 ms 91108 KB Output is correct
29 Correct 1452 ms 91048 KB Output is correct
30 Correct 1466 ms 90964 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Incorrect 54 ms 5648 KB Solution announced impossible, but it is possible.
33 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 424 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 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 752 ms 48984 KB Output is correct
10 Correct 48 ms 5212 KB Output is correct
11 Correct 368 ms 26560 KB Output is correct
12 Correct 75 ms 7516 KB Output is correct
13 Correct 268 ms 21840 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1340 KB Output is correct
16 Correct 745 ms 48776 KB Output is correct
17 Correct 1452 ms 92472 KB Output is correct
18 Correct 1445 ms 93264 KB Output is correct
19 Correct 974 ms 79444 KB Output is correct
20 Correct 1312 ms 77208 KB Output is correct
21 Correct 1280 ms 78948 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 156 ms 13908 KB Output is correct
24 Correct 83 ms 7764 KB Output is correct
25 Correct 359 ms 26452 KB Output is correct
26 Correct 720 ms 45204 KB Output is correct
27 Correct 560 ms 41096 KB Output is correct
28 Incorrect 740 ms 47072 KB Solution announced impossible, but it is possible.
29 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 424 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 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 752 ms 48984 KB Output is correct
10 Correct 48 ms 5212 KB Output is correct
11 Correct 368 ms 26560 KB Output is correct
12 Correct 75 ms 7516 KB Output is correct
13 Correct 268 ms 21840 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1340 KB Output is correct
16 Correct 745 ms 48776 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 0 ms 348 KB Output is correct
21 Correct 1 ms 436 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1717 ms 92104 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 5 ms 860 KB Output is correct
26 Correct 13 ms 1788 KB Output is correct
27 Correct 17 ms 2140 KB Output is correct
28 Correct 524 ms 36836 KB Output is correct
29 Correct 899 ms 55252 KB Output is correct
30 Correct 1322 ms 73648 KB Output is correct
31 Correct 1753 ms 91952 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 344 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 1 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 7 ms 1200 KB Output is correct
44 Correct 11 ms 1372 KB Output is correct
45 Correct 610 ms 43228 KB Output is correct
46 Correct 966 ms 62036 KB Output is correct
47 Correct 923 ms 62112 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 432 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1601 ms 84904 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 7 ms 1116 KB Output is correct
58 Correct 25 ms 2900 KB Output is correct
59 Correct 44 ms 4444 KB Output is correct
60 Correct 682 ms 42568 KB Output is correct
61 Correct 987 ms 57428 KB Output is correct
62 Correct 1271 ms 70224 KB Output is correct
63 Correct 1583 ms 85072 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 1645 ms 92100 KB Output is correct
68 Correct 1616 ms 91972 KB Output is correct
69 Correct 1490 ms 91476 KB Output is correct
70 Correct 14 ms 1884 KB Output is correct
71 Correct 31 ms 3420 KB Output is correct
72 Correct 587 ms 41976 KB Output is correct
73 Correct 986 ms 63056 KB Output is correct
74 Correct 1421 ms 83796 KB Output is correct
75 Correct 1595 ms 88896 KB Output is correct
76 Correct 1595 ms 91984 KB Output is correct
77 Correct 24 ms 2396 KB Output is correct
78 Correct 38 ms 3928 KB Output is correct
79 Correct 633 ms 44012 KB Output is correct
80 Correct 1054 ms 66128 KB Output is correct
81 Correct 1498 ms 87892 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 909 ms 79500 KB Output is correct
86 Correct 1068 ms 79304 KB Output is correct
87 Correct 907 ms 79440 KB Output is correct
88 Correct 1169 ms 78540 KB Output is correct
89 Correct 183 ms 22356 KB Output is correct
90 Correct 1383 ms 85064 KB Output is correct
91 Correct 1357 ms 85060 KB Output is correct
92 Correct 1418 ms 91220 KB Output is correct
93 Correct 1399 ms 91108 KB Output is correct
94 Correct 1452 ms 91048 KB Output is correct
95 Correct 1466 ms 90964 KB Output is correct
96 Correct 1 ms 348 KB Output is correct
97 Incorrect 54 ms 5648 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -