답안 #986967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986967 2024-05-21T16:12:35 Z pedroslrey 분수 공원 (IOI21_parks) C++17
5 / 100
777 ms 78852 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);
		}
	}

	vector<bool> marc(benches.size());
	vector<int> as(us.size()), bs(us.size());
	for (int i = 0; i < benches.size(); ++i) if (!marc[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:86: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]
   86 |  for (int i = 0; i < benches.size(); ++i) if (!marc[i]) {
      |                  ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 348 KB Output is correct
9 Correct 261 ms 39484 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 94 ms 20668 KB Output is correct
12 Correct 22 ms 6032 KB Output is correct
13 Correct 24 ms 4564 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 274 ms 38384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 348 KB Output is correct
9 Correct 261 ms 39484 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 94 ms 20668 KB Output is correct
12 Correct 22 ms 6032 KB Output is correct
13 Correct 24 ms 4564 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 274 ms 38384 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Incorrect 0 ms 348 KB a[4] = 0 is not an odd integer
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 348 KB Output is correct
9 Correct 261 ms 39484 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 94 ms 20668 KB Output is correct
12 Correct 22 ms 6032 KB Output is correct
13 Correct 24 ms 4564 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 274 ms 38384 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Incorrect 0 ms 348 KB a[4] = 0 is not an odd integer
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 348 KB Output is correct
9 Correct 261 ms 39484 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 94 ms 20668 KB Output is correct
12 Correct 22 ms 6032 KB Output is correct
13 Correct 24 ms 4564 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 274 ms 38384 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 504 KB Output is correct
20 Correct 557 ms 54184 KB Output is correct
21 Correct 607 ms 53608 KB Output is correct
22 Correct 541 ms 54440 KB Output is correct
23 Correct 524 ms 66716 KB Output is correct
24 Correct 204 ms 18376 KB Output is correct
25 Correct 255 ms 20164 KB Output is correct
26 Correct 274 ms 20296 KB Output is correct
27 Correct 658 ms 77724 KB Output is correct
28 Incorrect 680 ms 77724 KB a[54004] = 0 is not an odd integer
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 348 KB Output is correct
9 Correct 261 ms 39484 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 94 ms 20668 KB Output is correct
12 Correct 22 ms 6032 KB Output is correct
13 Correct 24 ms 4564 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 274 ms 38384 KB Output is correct
17 Correct 647 ms 76428 KB Output is correct
18 Correct 644 ms 78852 KB Output is correct
19 Correct 598 ms 53624 KB Output is correct
20 Incorrect 777 ms 63160 KB a[39838] = 0 is not an odd integer
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 348 KB Output is correct
9 Correct 261 ms 39484 KB Output is correct
10 Correct 15 ms 4236 KB Output is correct
11 Correct 94 ms 20668 KB Output is correct
12 Correct 22 ms 6032 KB Output is correct
13 Correct 24 ms 4564 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 274 ms 38384 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Incorrect 0 ms 348 KB a[4] = 0 is not an odd integer
21 Halted 0 ms 0 KB -