Submission #986972

# Submission time Handle Problem Language Result Execution time Memory
986972 2024-05-21T16:22:46 Z pedroslrey Fountain Parks (IOI21_parks) C++17
45 / 100
785 ms 78264 KB
#include <bits/stdc++.h>
#include "parks.h"

using namespace std;

int construct_roads(vector<int> xs, vector<int> ys) {
	int n = xs.size();

	map<pair<int, int>, int> points;
	for (int i = 0; i < n; ++i)
		points[make_pair(xs[i], ys[i])] = i;

	vector<int> rep(n); int comps = n;
	for (int i = 0; i < n; ++i)
		rep[i] = i;

	function<int (int)> find = [&rep, &find](int u) {
		if (rep[u] == u) return u;
		return rep[u] = find(rep[u]);
	};

	function<void (int, int)> une = [&rep, &comps, &find](int u, int v) {
		u = find(u); v = find(v);

		if (u == v) return;
		rep[u] = v;

		--comps;
	};

	vector<int> us, vs;
	for (int i = 0; i < n; ++i) {
		pair<int, int> lft{xs[i], ys[i] + 2}, up{xs[i] + 2, ys[i]};
		if (points.find(lft) != points.end()) {
			us.push_back(i);
			vs.push_back(points[lft]);
			une(us.back(), vs.back());
		}
		if (points.find(up) != points.end()) {
			us.push_back(i);
			vs.push_back(points[up]);
			une(us.back(), vs.back());
		}
	}

	if (comps > 1) return 0;

	map<pair<int, int>, int> mp;
	vector<pair<int, int>> benches;
	vector<vector<pair<int, int>>> graph;

	function<int (int, int)> vertex = [&mp, &graph, &benches](int x, int y) {
		pair<int, int> p{x, y};
		if (mp.find(p) == mp.end()) {
			benches.push_back(p);
			mp[p] = graph.size();
			graph.emplace_back();
		}

		return mp[p];
	};

	function<void (int, int, int)> add_edge = [&graph](int u, int v, int idx) {
		graph[u].emplace_back(v, idx);
		graph[v].emplace_back(u, idx);

		// cerr << "EDGE " << u << " " << v << " " << idx << "\n";
	};

	for (int i = 0; i < us.size(); ++i) {
		int x1 = xs[us[i]], y1 = ys[us[i]];
		int x2 = xs[vs[i]], y2 = ys[vs[i]];

		if (x1 == x2) {
			if (y1 > y2) swap(y1, y2);
			add_edge(vertex(x1 + 1, y1 + 1), vertex(x1 - 1, y1 + 1), i);
		}
		else {
			if (x1 > x2) swap(x1, x2);
			add_edge(vertex(x1 + 1, y1 + 1), vertex(x1 + 1, y1 - 1), i);
		}
	}

	for (auto &xs: graph) assert(xs.size() <= 2);

	vector<bool> marc(benches.size());
	vector<int> as(us.size()), bs(us.size());
	for (int i = 0; i < benches.size(); ++i) if (graph[i].size() == 1) {
		int u = i;
		while (!marc[u]) {
			marc[u] = true;
			for (auto [v, idx]: graph[u]) if (as[idx] == 0){
				as[idx] = benches[u].first;
				bs[idx] = benches[u].second;
				u = v;
				break;
			}
		}
	}

	for (int i = 0; i < benches.size(); ++i) {
		int u = i;
		while (!marc[u]) {
			marc[u] = true;
			for (auto [v, idx]: graph[u]) if (as[idx] == 0){
				as[idx] = benches[u].first;
				bs[idx] = benches[u].second;
				u = v;
				break;
			}
		}
	}

	build(us, vs, as, bs);

	return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:70:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |  for (int i = 0; i < us.size(); ++i) {
      |                  ~~^~~~~~~~~~~
parks.cpp:88:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |  for (int i = 0; i < benches.size(); ++i) if (graph[i].size() == 1) {
      |                  ~~^~~~~~~~~~~~~~~~
parks.cpp:101:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |  for (int i = 0; i < benches.size(); ++i) {
      |                  ~~^~~~~~~~~~~~~~~~
# 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 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 344 KB Output is correct
9 Correct 264 ms 38748 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 110 ms 20692 KB Output is correct
12 Correct 23 ms 6028 KB Output is correct
13 Correct 24 ms 4560 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 262 ms 38184 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 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 344 KB Output is correct
9 Correct 264 ms 38748 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 110 ms 20692 KB Output is correct
12 Correct 23 ms 6028 KB Output is correct
13 Correct 24 ms 4560 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 262 ms 38184 KB Output is correct
17 Runtime error 1 ms 344 KB Execution killed with signal 6
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 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 344 KB Output is correct
9 Correct 264 ms 38748 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 110 ms 20692 KB Output is correct
12 Correct 23 ms 6028 KB Output is correct
13 Correct 24 ms 4560 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 262 ms 38184 KB Output is correct
17 Runtime error 1 ms 344 KB Execution killed with signal 6
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 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 344 KB Output is correct
9 Correct 264 ms 38748 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 110 ms 20692 KB Output is correct
12 Correct 23 ms 6028 KB Output is correct
13 Correct 24 ms 4560 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 262 ms 38184 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 396 KB Output is correct
20 Correct 601 ms 52468 KB Output is correct
21 Correct 618 ms 51128 KB Output is correct
22 Correct 582 ms 51116 KB Output is correct
23 Correct 534 ms 64860 KB Output is correct
24 Correct 198 ms 16724 KB Output is correct
25 Correct 291 ms 18640 KB Output is correct
26 Correct 248 ms 18632 KB Output is correct
27 Correct 657 ms 76444 KB Output is correct
28 Correct 681 ms 76188 KB Output is correct
29 Correct 658 ms 77716 KB Output is correct
30 Correct 705 ms 77716 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 29 ms 4492 KB Output is correct
33 Correct 81 ms 9812 KB Output is correct
34 Correct 595 ms 54048 KB Output is correct
35 Correct 8 ms 1372 KB Output is correct
36 Correct 45 ms 5668 KB Output is correct
37 Correct 103 ms 10800 KB Output is correct
38 Correct 195 ms 24112 KB Output is correct
39 Correct 302 ms 32228 KB Output is correct
40 Correct 396 ms 41216 KB Output is correct
41 Correct 531 ms 49836 KB Output is correct
42 Correct 677 ms 59088 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 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 1 ms 388 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 2 ms 604 KB Output is correct
56 Correct 254 ms 32876 KB Output is correct
57 Correct 428 ms 46252 KB Output is correct
58 Correct 434 ms 46500 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 648 ms 78264 KB Output is correct
63 Correct 625 ms 78092 KB Output is correct
64 Correct 658 ms 77648 KB Output is correct
65 Correct 3 ms 600 KB Output is correct
66 Correct 5 ms 1116 KB Output is correct
67 Correct 250 ms 31536 KB Output is correct
68 Correct 475 ms 45896 KB Output is correct
69 Correct 670 ms 61088 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 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 344 KB Output is correct
9 Correct 264 ms 38748 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 110 ms 20692 KB Output is correct
12 Correct 23 ms 6028 KB Output is correct
13 Correct 24 ms 4560 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 262 ms 38184 KB Output is correct
17 Correct 690 ms 76332 KB Output is correct
18 Correct 646 ms 76580 KB Output is correct
19 Correct 613 ms 51248 KB Output is correct
20 Correct 785 ms 61556 KB Output is correct
21 Correct 642 ms 64412 KB Output is correct
22 Correct 0 ms 600 KB Output is correct
23 Correct 70 ms 10120 KB Output is correct
24 Correct 18 ms 2396 KB Output is correct
25 Correct 71 ms 7980 KB Output is correct
26 Correct 142 ms 13672 KB Output is correct
27 Correct 283 ms 31800 KB Output is correct
28 Correct 461 ms 40660 KB Output is correct
29 Correct 530 ms 48752 KB Output is correct
30 Correct 669 ms 55760 KB Output is correct
31 Correct 778 ms 63468 KB Output is correct
32 Correct 771 ms 69744 KB Output is correct
33 Correct 633 ms 77852 KB Output is correct
34 Correct 3 ms 860 KB Output is correct
35 Correct 6 ms 1368 KB Output is correct
36 Correct 268 ms 32756 KB Output is correct
37 Correct 541 ms 48668 KB Output is correct
38 Correct 732 ms 64780 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 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 344 KB Output is correct
9 Correct 264 ms 38748 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 110 ms 20692 KB Output is correct
12 Correct 23 ms 6028 KB Output is correct
13 Correct 24 ms 4560 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 262 ms 38184 KB Output is correct
17 Runtime error 1 ms 344 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -