답안 #925406

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925406 2024-02-11T14:52:01 Z Itamar 분수 공원 (IOI21_parks) C++17
45 / 100
1177 ms 116888 KB
using namespace std;
#include <vector>
#include "parks.h"
#include <map>
#define pi pair<int,int>
#define vi vector<int>
const int siz = 2e5 + 2;
map<pi, int> m;
int my[siz];
vi col[siz];
#include <set>
bool con(int a, int b) {
	if (my[a] == my[b])return 0;
	a = my[a], b = my[b];
	if (col[a].size() > col[b].size())swap(a, b);
	for (int x : col[a]) {
		my[x] = b;
		col[b].push_back(x);
	}
	return 1;
}

int construct_roads(std::vector<int> x, std::vector<int> y) {
	int n = x.size();
	for (int i = 0; i < n; i++) {
		m[{x[i], y[i]}] = i + 1;
	}
	vector<pi> ed1, ed2;
	for (int i = 0; i < n; i++) {
		if (m[{x[i] + 2, y[i]}])ed2.push_back({ i+1,m[{x[i] + 2, y[i]}] });
		if (m[{x[i], y[i] + 2}])ed1.push_back({ i+1,m[{x[i],y[i] + 2}] });
	}
	vector<pi> ed; for (pi p : ed2)ed.push_back(p); for (pi p : ed1)ed.push_back(p);
	vector<pi> ans;
	for (int i = 0; i <= n; i++) {
		my[i] = i; col[i].push_back(i);
	}
	for (pi e : ed) {
		if (con(e.first, e.second))ans.push_back(e);
	}
	if (ans.size()+1 < n )return 0;
	vi ans1(n - 1), ans2(n - 1), ans3(n - 1), ans4(n - 1);

	for (int i = 0; i < n - 1; i++) {
		ans1[i] = ans[i].first - 1; ans2[i] = ans[i].second - 1;
	}
	map<pi, vi> fr;
	vector<vector<pi>> fr2(n - 1);
	for (int i = 0; i < n - 1; i++) {
		if (x[ans[i].first - 1] == x[ans[i].second - 1]) {
			int mid = (y[ans[i].first - 1] + y[ans[i].second - 1]) / 2;
			fr[{x[ans[i].first - 1]-1, mid}].push_back(i);
			fr[{x[ans[i].first - 1]+1, mid}].push_back(i);
			fr2[i].push_back({ x[ans[i].first - 1]-1, mid });
			fr2[i].push_back({ x[ans[i].first - 1]+1, mid });
		}
		else {
			int mid = (x[ans[i].first - 1] + x[ans[i].second - 1]) / 2;
			fr[{mid,y[ans[i].first - 1]+1}].push_back(i);
			fr[{mid,y[ans[i].first - 1]-1}].push_back(i);
			fr2[i].push_back( {mid,y[ans[i].first - 1]-1 });
			fr2[i].push_back( {mid,y[ans[i].first - 1]+1} );
		}
	}
	for (pair<pi,vi> p : fr) {
		pi poi = p.first;
			while (fr[poi].size() == 1) {
				int i = fr[poi][0];
				fr[poi].pop_back();
				if (fr2[i].back() != poi)swap(fr2[i][0], fr2[i][1]);
				fr2[i].pop_back();
				ans3[i] = poi.first, ans4[i] = poi.second;
				if (fr2[i].size() == 1) {
					poi = fr2[i][0];
					if (fr[poi].size()) {
						if (fr[poi].back() != i)swap(fr[poi][0], fr[poi][1]);
						fr[poi].pop_back();
					}
				}
			}
	}
	for (pair<pi, vi> p : fr) {
		pi poi = p.first;
		if (p.second.size() == 2)fr[poi].pop_back();
		while (fr[poi].size() == 1) {
			int i = fr[poi][0];
			fr[poi].pop_back();
			if (fr2[i].back() != poi)swap(fr2[i][0], fr2[i][1]);
			fr2[i].pop_back();
			ans3[i] = poi.first, ans4[i] = poi.second;
			if (fr2[i].size() == 1) {
				poi = fr2[i][0];
				if (fr[poi].size()) {
					if (fr[poi].back() != i)swap(fr[poi][0], fr[poi][1]);
					fr[poi].pop_back();
				}
			}
		}
	}
	build(ans1, ans2, ans3, ans4);
	return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:42:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |  if (ans.size()+1 < n )return 0;
      |      ~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 3 ms 5468 KB Output is correct
3 Correct 4 ms 5468 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5464 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 414 ms 60644 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 148 ms 34124 KB Output is correct
12 Correct 36 ms 13396 KB Output is correct
13 Correct 33 ms 15012 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5980 KB Output is correct
16 Correct 422 ms 61000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 3 ms 5468 KB Output is correct
3 Correct 4 ms 5468 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5464 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 414 ms 60644 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 148 ms 34124 KB Output is correct
12 Correct 36 ms 13396 KB Output is correct
13 Correct 33 ms 15012 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5980 KB Output is correct
16 Correct 422 ms 61000 KB Output is correct
17 Correct 2 ms 5468 KB Output is correct
18 Correct 1 ms 5468 KB Output is correct
19 Correct 2 ms 5408 KB Output is correct
20 Correct 1 ms 5468 KB Output is correct
21 Correct 1 ms 5468 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Incorrect 833 ms 90884 KB a[96849] = 0 is not an odd integer
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 3 ms 5468 KB Output is correct
3 Correct 4 ms 5468 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5464 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 414 ms 60644 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 148 ms 34124 KB Output is correct
12 Correct 36 ms 13396 KB Output is correct
13 Correct 33 ms 15012 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5980 KB Output is correct
16 Correct 422 ms 61000 KB Output is correct
17 Correct 2 ms 5468 KB Output is correct
18 Correct 1 ms 5468 KB Output is correct
19 Correct 2 ms 5408 KB Output is correct
20 Correct 1 ms 5468 KB Output is correct
21 Correct 1 ms 5468 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Incorrect 833 ms 90884 KB a[96849] = 0 is not an odd integer
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 3 ms 5468 KB Output is correct
3 Correct 4 ms 5468 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5464 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 414 ms 60644 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 148 ms 34124 KB Output is correct
12 Correct 36 ms 13396 KB Output is correct
13 Correct 33 ms 15012 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5980 KB Output is correct
16 Correct 422 ms 61000 KB Output is correct
17 Correct 2 ms 5468 KB Output is correct
18 Correct 1 ms 5468 KB Output is correct
19 Correct 2 ms 5720 KB Output is correct
20 Correct 765 ms 89100 KB Output is correct
21 Correct 852 ms 95592 KB Output is correct
22 Correct 789 ms 89524 KB Output is correct
23 Correct 725 ms 100028 KB Output is correct
24 Correct 397 ms 54956 KB Output is correct
25 Correct 357 ms 50496 KB Output is correct
26 Correct 353 ms 50368 KB Output is correct
27 Correct 989 ms 113724 KB Output is correct
28 Correct 1004 ms 113928 KB Output is correct
29 Correct 884 ms 116028 KB Output is correct
30 Correct 942 ms 116244 KB Output is correct
31 Correct 1 ms 5464 KB Output is correct
32 Correct 37 ms 11844 KB Output is correct
33 Correct 119 ms 30184 KB Output is correct
34 Correct 773 ms 95400 KB Output is correct
35 Correct 10 ms 7516 KB Output is correct
36 Correct 60 ms 15924 KB Output is correct
37 Correct 130 ms 26308 KB Output is correct
38 Correct 239 ms 40360 KB Output is correct
39 Correct 391 ms 53700 KB Output is correct
40 Correct 590 ms 67124 KB Output is correct
41 Correct 769 ms 79968 KB Output is correct
42 Correct 868 ms 93240 KB Output is correct
43 Correct 2 ms 5464 KB Output is correct
44 Correct 2 ms 5468 KB Output is correct
45 Correct 1 ms 5468 KB Output is correct
46 Correct 1 ms 5468 KB Output is correct
47 Correct 2 ms 5468 KB Output is correct
48 Correct 2 ms 5468 KB Output is correct
49 Correct 2 ms 5476 KB Output is correct
50 Correct 2 ms 5468 KB Output is correct
51 Correct 2 ms 5468 KB Output is correct
52 Correct 1 ms 5468 KB Output is correct
53 Correct 2 ms 5468 KB Output is correct
54 Correct 3 ms 5948 KB Output is correct
55 Correct 4 ms 5980 KB Output is correct
56 Correct 390 ms 52948 KB Output is correct
57 Correct 671 ms 74516 KB Output is correct
58 Correct 735 ms 74392 KB Output is correct
59 Correct 2 ms 5468 KB Output is correct
60 Correct 1 ms 5468 KB Output is correct
61 Correct 1 ms 5468 KB Output is correct
62 Correct 1177 ms 116456 KB Output is correct
63 Correct 1120 ms 116888 KB Output is correct
64 Correct 1085 ms 116036 KB Output is correct
65 Correct 4 ms 6232 KB Output is correct
66 Correct 8 ms 7080 KB Output is correct
67 Correct 416 ms 51916 KB Output is correct
68 Correct 700 ms 75512 KB Output is correct
69 Correct 1059 ms 99296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 3 ms 5468 KB Output is correct
3 Correct 4 ms 5468 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5464 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 414 ms 60644 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 148 ms 34124 KB Output is correct
12 Correct 36 ms 13396 KB Output is correct
13 Correct 33 ms 15012 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5980 KB Output is correct
16 Correct 422 ms 61000 KB Output is correct
17 Correct 924 ms 116692 KB Output is correct
18 Correct 921 ms 116708 KB Output is correct
19 Correct 916 ms 92048 KB Output is correct
20 Correct 872 ms 91600 KB Output is correct
21 Correct 908 ms 92120 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Correct 101 ms 19364 KB Output is correct
24 Correct 20 ms 9768 KB Output is correct
25 Correct 84 ms 19804 KB Output is correct
26 Correct 159 ms 29464 KB Output is correct
27 Correct 417 ms 49124 KB Output is correct
28 Correct 497 ms 60356 KB Output is correct
29 Correct 665 ms 71376 KB Output is correct
30 Correct 824 ms 82100 KB Output is correct
31 Correct 992 ms 93472 KB Output is correct
32 Correct 965 ms 98932 KB Output is correct
33 Correct 1106 ms 116504 KB Output is correct
34 Correct 7 ms 6568 KB Output is correct
35 Correct 11 ms 7276 KB Output is correct
36 Correct 384 ms 51292 KB Output is correct
37 Correct 672 ms 74496 KB Output is correct
38 Correct 1099 ms 97980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 3 ms 5468 KB Output is correct
3 Correct 4 ms 5468 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5464 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 414 ms 60644 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 148 ms 34124 KB Output is correct
12 Correct 36 ms 13396 KB Output is correct
13 Correct 33 ms 15012 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5980 KB Output is correct
16 Correct 422 ms 61000 KB Output is correct
17 Correct 2 ms 5468 KB Output is correct
18 Correct 1 ms 5468 KB Output is correct
19 Correct 2 ms 5408 KB Output is correct
20 Correct 1 ms 5468 KB Output is correct
21 Correct 1 ms 5468 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Incorrect 833 ms 90884 KB a[96849] = 0 is not an odd integer
24 Halted 0 ms 0 KB -