답안 #1059634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1059634 2024-08-15T06:32:56 Z Gromp15 분수 공원 (IOI21_parks) C++17
30 / 100
1764 ms 93332 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 (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++;
					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;
}
# 결과 실행 시간 메모리 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 0 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 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 739 ms 48904 KB Output is correct
10 Correct 50 ms 5204 KB Output is correct
11 Correct 349 ms 26452 KB Output is correct
12 Correct 78 ms 7672 KB Output is correct
13 Correct 274 ms 21760 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1404 KB Output is correct
16 Correct 755 ms 48828 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 0 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 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 739 ms 48904 KB Output is correct
10 Correct 50 ms 5204 KB Output is correct
11 Correct 349 ms 26452 KB Output is correct
12 Correct 78 ms 7672 KB Output is correct
13 Correct 274 ms 21760 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1404 KB Output is correct
16 Correct 755 ms 48828 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1740 ms 91956 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 5 ms 972 KB Output is correct
26 Correct 13 ms 1628 KB Output is correct
27 Correct 18 ms 2108 KB Output is correct
28 Correct 560 ms 36944 KB Output is correct
29 Correct 897 ms 55380 KB Output is correct
30 Correct 1304 ms 73808 KB Output is correct
31 Correct 1764 ms 91988 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 600 KB Output is correct
34 Correct 0 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 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 7 ms 1116 KB Output is correct
44 Correct 11 ms 1624 KB Output is correct
45 Correct 608 ms 43092 KB Output is correct
46 Correct 957 ms 62292 KB Output is correct
47 Correct 949 ms 62260 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 0 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 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 739 ms 48904 KB Output is correct
10 Correct 50 ms 5204 KB Output is correct
11 Correct 349 ms 26452 KB Output is correct
12 Correct 78 ms 7672 KB Output is correct
13 Correct 274 ms 21760 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1404 KB Output is correct
16 Correct 755 ms 48828 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1740 ms 91956 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 5 ms 972 KB Output is correct
26 Correct 13 ms 1628 KB Output is correct
27 Correct 18 ms 2108 KB Output is correct
28 Correct 560 ms 36944 KB Output is correct
29 Correct 897 ms 55380 KB Output is correct
30 Correct 1304 ms 73808 KB Output is correct
31 Correct 1764 ms 91988 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 600 KB Output is correct
34 Correct 0 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 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 7 ms 1116 KB Output is correct
44 Correct 11 ms 1624 KB Output is correct
45 Correct 608 ms 43092 KB Output is correct
46 Correct 957 ms 62292 KB Output is correct
47 Correct 949 ms 62260 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 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 344 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1636 ms 85016 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 7 ms 1116 KB Output is correct
58 Correct 26 ms 2908 KB Output is correct
59 Correct 46 ms 4616 KB Output is correct
60 Correct 683 ms 42580 KB Output is correct
61 Correct 1016 ms 57424 KB Output is correct
62 Correct 1303 ms 70312 KB Output is correct
63 Correct 1657 ms 84996 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 1619 ms 91944 KB Output is correct
68 Correct 1618 ms 91988 KB Output is correct
69 Correct 1539 ms 91624 KB Output is correct
70 Correct 15 ms 1880 KB Output is correct
71 Correct 31 ms 3524 KB Output is correct
72 Correct 594 ms 42000 KB Output is correct
73 Correct 954 ms 63056 KB Output is correct
74 Correct 1368 ms 83796 KB Output is correct
75 Correct 1578 ms 88912 KB Output is correct
76 Correct 1594 ms 91988 KB Output is correct
77 Correct 20 ms 2392 KB Output is correct
78 Correct 38 ms 3980 KB Output is correct
79 Correct 620 ms 44112 KB Output is correct
80 Correct 1061 ms 66132 KB Output is correct
81 Correct 1475 ms 87996 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 0 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 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 739 ms 48904 KB Output is correct
10 Correct 50 ms 5204 KB Output is correct
11 Correct 349 ms 26452 KB Output is correct
12 Correct 78 ms 7672 KB Output is correct
13 Correct 274 ms 21760 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1404 KB Output is correct
16 Correct 755 ms 48828 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 863 ms 79532 KB Output is correct
21 Correct 1102 ms 79444 KB Output is correct
22 Correct 966 ms 79448 KB Output is correct
23 Correct 1270 ms 78584 KB Output is correct
24 Correct 247 ms 22448 KB Output is correct
25 Correct 1584 ms 84924 KB Output is correct
26 Correct 1503 ms 84928 KB Output is correct
27 Correct 1430 ms 91192 KB Output is correct
28 Correct 1421 ms 91220 KB Output is correct
29 Correct 1440 ms 91124 KB Output is correct
30 Correct 1450 ms 91012 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Incorrect 56 ms 5584 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 0 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 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 739 ms 48904 KB Output is correct
10 Correct 50 ms 5204 KB Output is correct
11 Correct 349 ms 26452 KB Output is correct
12 Correct 78 ms 7672 KB Output is correct
13 Correct 274 ms 21760 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1404 KB Output is correct
16 Correct 755 ms 48828 KB Output is correct
17 Correct 1552 ms 92428 KB Output is correct
18 Correct 1435 ms 93332 KB Output is correct
19 Correct 973 ms 79444 KB Output is correct
20 Correct 1352 ms 77244 KB Output is correct
21 Correct 1268 ms 78872 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 141 ms 13904 KB Output is correct
24 Correct 85 ms 7760 KB Output is correct
25 Correct 361 ms 26448 KB Output is correct
26 Correct 683 ms 45012 KB Output is correct
27 Correct 578 ms 40880 KB Output is correct
28 Incorrect 781 ms 46932 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 0 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 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 739 ms 48904 KB Output is correct
10 Correct 50 ms 5204 KB Output is correct
11 Correct 349 ms 26452 KB Output is correct
12 Correct 78 ms 7672 KB Output is correct
13 Correct 274 ms 21760 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 8 ms 1404 KB Output is correct
16 Correct 755 ms 48828 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1740 ms 91956 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 5 ms 972 KB Output is correct
26 Correct 13 ms 1628 KB Output is correct
27 Correct 18 ms 2108 KB Output is correct
28 Correct 560 ms 36944 KB Output is correct
29 Correct 897 ms 55380 KB Output is correct
30 Correct 1304 ms 73808 KB Output is correct
31 Correct 1764 ms 91988 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 600 KB Output is correct
34 Correct 0 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 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 7 ms 1116 KB Output is correct
44 Correct 11 ms 1624 KB Output is correct
45 Correct 608 ms 43092 KB Output is correct
46 Correct 957 ms 62292 KB Output is correct
47 Correct 949 ms 62260 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 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 344 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1636 ms 85016 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 7 ms 1116 KB Output is correct
58 Correct 26 ms 2908 KB Output is correct
59 Correct 46 ms 4616 KB Output is correct
60 Correct 683 ms 42580 KB Output is correct
61 Correct 1016 ms 57424 KB Output is correct
62 Correct 1303 ms 70312 KB Output is correct
63 Correct 1657 ms 84996 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 1619 ms 91944 KB Output is correct
68 Correct 1618 ms 91988 KB Output is correct
69 Correct 1539 ms 91624 KB Output is correct
70 Correct 15 ms 1880 KB Output is correct
71 Correct 31 ms 3524 KB Output is correct
72 Correct 594 ms 42000 KB Output is correct
73 Correct 954 ms 63056 KB Output is correct
74 Correct 1368 ms 83796 KB Output is correct
75 Correct 1578 ms 88912 KB Output is correct
76 Correct 1594 ms 91988 KB Output is correct
77 Correct 20 ms 2392 KB Output is correct
78 Correct 38 ms 3980 KB Output is correct
79 Correct 620 ms 44112 KB Output is correct
80 Correct 1061 ms 66132 KB Output is correct
81 Correct 1475 ms 87996 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 0 ms 344 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 863 ms 79532 KB Output is correct
86 Correct 1102 ms 79444 KB Output is correct
87 Correct 966 ms 79448 KB Output is correct
88 Correct 1270 ms 78584 KB Output is correct
89 Correct 247 ms 22448 KB Output is correct
90 Correct 1584 ms 84924 KB Output is correct
91 Correct 1503 ms 84928 KB Output is correct
92 Correct 1430 ms 91192 KB Output is correct
93 Correct 1421 ms 91220 KB Output is correct
94 Correct 1440 ms 91124 KB Output is correct
95 Correct 1450 ms 91012 KB Output is correct
96 Correct 0 ms 344 KB Output is correct
97 Incorrect 56 ms 5584 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -