답안 #986969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986969 2024-05-21T16:14:45 Z pedroslrey 분수 공원 (IOI21_parks) C++17
5 / 100
817 ms 76188 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 (!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: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 (!marc[i]) {
      |                  ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 258 ms 38432 KB Output is correct
10 Correct 15 ms 4240 KB Output is correct
11 Correct 93 ms 20732 KB Output is correct
12 Correct 23 ms 6032 KB Output is correct
13 Correct 24 ms 4568 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 284 ms 38460 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 258 ms 38432 KB Output is correct
10 Correct 15 ms 4240 KB Output is correct
11 Correct 93 ms 20732 KB Output is correct
12 Correct 23 ms 6032 KB Output is correct
13 Correct 24 ms 4568 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 284 ms 38460 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 6
18 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 258 ms 38432 KB Output is correct
10 Correct 15 ms 4240 KB Output is correct
11 Correct 93 ms 20732 KB Output is correct
12 Correct 23 ms 6032 KB Output is correct
13 Correct 24 ms 4568 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 284 ms 38460 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 6
18 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 258 ms 38432 KB Output is correct
10 Correct 15 ms 4240 KB Output is correct
11 Correct 93 ms 20732 KB Output is correct
12 Correct 23 ms 6032 KB Output is correct
13 Correct 24 ms 4568 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 284 ms 38460 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 590 ms 51336 KB Output is correct
21 Correct 658 ms 51184 KB Output is correct
22 Correct 537 ms 52020 KB Output is correct
23 Correct 514 ms 64980 KB Output is correct
24 Correct 214 ms 16980 KB Output is correct
25 Correct 260 ms 18576 KB Output is correct
26 Correct 265 ms 18504 KB Output is correct
27 Correct 658 ms 76152 KB Output is correct
28 Incorrect 657 ms 76144 KB a[54004] = 0 is not an odd integer
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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 258 ms 38432 KB Output is correct
10 Correct 15 ms 4240 KB Output is correct
11 Correct 93 ms 20732 KB Output is correct
12 Correct 23 ms 6032 KB Output is correct
13 Correct 24 ms 4568 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 284 ms 38460 KB Output is correct
17 Correct 649 ms 76188 KB Output is correct
18 Correct 650 ms 76188 KB Output is correct
19 Correct 612 ms 51116 KB Output is correct
20 Incorrect 817 ms 61592 KB a[39838] = 0 is not an odd integer
21 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 258 ms 38432 KB Output is correct
10 Correct 15 ms 4240 KB Output is correct
11 Correct 93 ms 20732 KB Output is correct
12 Correct 23 ms 6032 KB Output is correct
13 Correct 24 ms 4568 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 284 ms 38460 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -