답안 #1059641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1059641 2024-08-15T06:38:02 Z Gromp15 분수 공원 (IOI21_parks) C++17
30 / 100
2001 ms 93456 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]}];
				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]--;
				if (!F && D.get(i1) != D.get(i2)) {
					F = 1;
					D.merge(i1, i2);
					a[now] = i1, b[now] = i2;
					c[now] = p[0], d[now] = p[1];
					now++;
				}
			}
		}
		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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 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 898 ms 49004 KB Output is correct
10 Correct 57 ms 5204 KB Output is correct
11 Correct 484 ms 26456 KB Output is correct
12 Correct 93 ms 7504 KB Output is correct
13 Correct 350 ms 21696 KB Output is correct
14 Correct 4 ms 856 KB Output is correct
15 Correct 9 ms 1216 KB Output is correct
16 Correct 850 ms 48824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 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 898 ms 49004 KB Output is correct
10 Correct 57 ms 5204 KB Output is correct
11 Correct 484 ms 26456 KB Output is correct
12 Correct 93 ms 7504 KB Output is correct
13 Correct 350 ms 21696 KB Output is correct
14 Correct 4 ms 856 KB Output is correct
15 Correct 9 ms 1216 KB Output is correct
16 Correct 850 ms 48824 KB Output is correct
17 Correct 0 ms 344 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 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2001 ms 91880 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 6 ms 860 KB Output is correct
26 Correct 14 ms 1792 KB Output is correct
27 Correct 20 ms 2136 KB Output is correct
28 Correct 653 ms 36932 KB Output is correct
29 Correct 1039 ms 55448 KB Output is correct
30 Correct 1520 ms 73676 KB Output is correct
31 Correct 1998 ms 92104 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 436 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 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 15 ms 1220 KB Output is correct
44 Correct 12 ms 1628 KB Output is correct
45 Correct 667 ms 43052 KB Output is correct
46 Correct 1063 ms 62092 KB Output is correct
47 Correct 1051 ms 62032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 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 898 ms 49004 KB Output is correct
10 Correct 57 ms 5204 KB Output is correct
11 Correct 484 ms 26456 KB Output is correct
12 Correct 93 ms 7504 KB Output is correct
13 Correct 350 ms 21696 KB Output is correct
14 Correct 4 ms 856 KB Output is correct
15 Correct 9 ms 1216 KB Output is correct
16 Correct 850 ms 48824 KB Output is correct
17 Correct 0 ms 344 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 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2001 ms 91880 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 6 ms 860 KB Output is correct
26 Correct 14 ms 1792 KB Output is correct
27 Correct 20 ms 2136 KB Output is correct
28 Correct 653 ms 36932 KB Output is correct
29 Correct 1039 ms 55448 KB Output is correct
30 Correct 1520 ms 73676 KB Output is correct
31 Correct 1998 ms 92104 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 436 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 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 15 ms 1220 KB Output is correct
44 Correct 12 ms 1628 KB Output is correct
45 Correct 667 ms 43052 KB Output is correct
46 Correct 1063 ms 62092 KB Output is correct
47 Correct 1051 ms 62032 KB Output is correct
48 Correct 0 ms 348 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 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1881 ms 84856 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 8 ms 1112 KB Output is correct
58 Correct 31 ms 2904 KB Output is correct
59 Correct 54 ms 4440 KB Output is correct
60 Correct 814 ms 42680 KB Output is correct
61 Correct 1215 ms 57428 KB Output is correct
62 Correct 1484 ms 70228 KB Output is correct
63 Correct 1907 ms 85076 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 1862 ms 92100 KB Output is correct
68 Correct 1874 ms 91904 KB Output is correct
69 Correct 1766 ms 91588 KB Output is correct
70 Correct 17 ms 1880 KB Output is correct
71 Correct 42 ms 3488 KB Output is correct
72 Correct 669 ms 42064 KB Output is correct
73 Correct 1105 ms 63060 KB Output is correct
74 Correct 1562 ms 83796 KB Output is correct
75 Correct 1816 ms 88868 KB Output is correct
76 Correct 1812 ms 92000 KB Output is correct
77 Correct 23 ms 2392 KB Output is correct
78 Correct 43 ms 3932 KB Output is correct
79 Correct 682 ms 44112 KB Output is correct
80 Correct 1188 ms 66132 KB Output is correct
81 Correct 1695 ms 88144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 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 898 ms 49004 KB Output is correct
10 Correct 57 ms 5204 KB Output is correct
11 Correct 484 ms 26456 KB Output is correct
12 Correct 93 ms 7504 KB Output is correct
13 Correct 350 ms 21696 KB Output is correct
14 Correct 4 ms 856 KB Output is correct
15 Correct 9 ms 1216 KB Output is correct
16 Correct 850 ms 48824 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 436 KB Output is correct
19 Correct 0 ms 436 KB Output is correct
20 Correct 990 ms 79632 KB Output is correct
21 Correct 1125 ms 79440 KB Output is correct
22 Correct 1014 ms 79428 KB Output is correct
23 Correct 1267 ms 78588 KB Output is correct
24 Correct 189 ms 22296 KB Output is correct
25 Correct 1478 ms 85168 KB Output is correct
26 Correct 1572 ms 85120 KB Output is correct
27 Correct 1613 ms 91124 KB Output is correct
28 Correct 1606 ms 91248 KB Output is correct
29 Correct 1562 ms 91236 KB Output is correct
30 Correct 1578 ms 90960 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Incorrect 64 ms 5716 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 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 898 ms 49004 KB Output is correct
10 Correct 57 ms 5204 KB Output is correct
11 Correct 484 ms 26456 KB Output is correct
12 Correct 93 ms 7504 KB Output is correct
13 Correct 350 ms 21696 KB Output is correct
14 Correct 4 ms 856 KB Output is correct
15 Correct 9 ms 1216 KB Output is correct
16 Correct 850 ms 48824 KB Output is correct
17 Correct 1679 ms 92428 KB Output is correct
18 Correct 1660 ms 93456 KB Output is correct
19 Correct 1187 ms 79444 KB Output is correct
20 Correct 1545 ms 77136 KB Output is correct
21 Correct 1397 ms 78928 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 169 ms 13980 KB Output is correct
24 Correct 101 ms 7868 KB Output is correct
25 Correct 427 ms 26388 KB Output is correct
26 Correct 806 ms 45120 KB Output is correct
27 Correct 661 ms 40676 KB Output is correct
28 Incorrect 867 ms 47184 KB Solution announced impossible, but it is possible.
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 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 898 ms 49004 KB Output is correct
10 Correct 57 ms 5204 KB Output is correct
11 Correct 484 ms 26456 KB Output is correct
12 Correct 93 ms 7504 KB Output is correct
13 Correct 350 ms 21696 KB Output is correct
14 Correct 4 ms 856 KB Output is correct
15 Correct 9 ms 1216 KB Output is correct
16 Correct 850 ms 48824 KB Output is correct
17 Correct 0 ms 344 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 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2001 ms 91880 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 6 ms 860 KB Output is correct
26 Correct 14 ms 1792 KB Output is correct
27 Correct 20 ms 2136 KB Output is correct
28 Correct 653 ms 36932 KB Output is correct
29 Correct 1039 ms 55448 KB Output is correct
30 Correct 1520 ms 73676 KB Output is correct
31 Correct 1998 ms 92104 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 436 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 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 15 ms 1220 KB Output is correct
44 Correct 12 ms 1628 KB Output is correct
45 Correct 667 ms 43052 KB Output is correct
46 Correct 1063 ms 62092 KB Output is correct
47 Correct 1051 ms 62032 KB Output is correct
48 Correct 0 ms 348 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 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1881 ms 84856 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 8 ms 1112 KB Output is correct
58 Correct 31 ms 2904 KB Output is correct
59 Correct 54 ms 4440 KB Output is correct
60 Correct 814 ms 42680 KB Output is correct
61 Correct 1215 ms 57428 KB Output is correct
62 Correct 1484 ms 70228 KB Output is correct
63 Correct 1907 ms 85076 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 1862 ms 92100 KB Output is correct
68 Correct 1874 ms 91904 KB Output is correct
69 Correct 1766 ms 91588 KB Output is correct
70 Correct 17 ms 1880 KB Output is correct
71 Correct 42 ms 3488 KB Output is correct
72 Correct 669 ms 42064 KB Output is correct
73 Correct 1105 ms 63060 KB Output is correct
74 Correct 1562 ms 83796 KB Output is correct
75 Correct 1816 ms 88868 KB Output is correct
76 Correct 1812 ms 92000 KB Output is correct
77 Correct 23 ms 2392 KB Output is correct
78 Correct 43 ms 3932 KB Output is correct
79 Correct 682 ms 44112 KB Output is correct
80 Correct 1188 ms 66132 KB Output is correct
81 Correct 1695 ms 88144 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 436 KB Output is correct
84 Correct 0 ms 436 KB Output is correct
85 Correct 990 ms 79632 KB Output is correct
86 Correct 1125 ms 79440 KB Output is correct
87 Correct 1014 ms 79428 KB Output is correct
88 Correct 1267 ms 78588 KB Output is correct
89 Correct 189 ms 22296 KB Output is correct
90 Correct 1478 ms 85168 KB Output is correct
91 Correct 1572 ms 85120 KB Output is correct
92 Correct 1613 ms 91124 KB Output is correct
93 Correct 1606 ms 91248 KB Output is correct
94 Correct 1562 ms 91236 KB Output is correct
95 Correct 1578 ms 90960 KB Output is correct
96 Correct 1 ms 344 KB Output is correct
97 Incorrect 64 ms 5716 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -