Submission #925409

# Submission time Handle Problem Language Result Execution time Memory
925409 2024-02-11T14:55:08 Z Itamar Fountain Parks (IOI21_parks) C++17
45 / 100
1032 ms 115124 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]}])ed1.push_back({ i+1,m[{x[i] + 2, y[i]}] });
		if (m[{x[i], y[i] + 2}])ed2.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;
      |      ~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5516 KB Output is correct
3 Correct 1 ms 5468 KB Output is correct
4 Correct 1 ms 5468 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5468 KB Output is correct
7 Correct 1 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 415 ms 59816 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 141 ms 33356 KB Output is correct
12 Correct 37 ms 13120 KB Output is correct
13 Correct 36 ms 14672 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 418 ms 59720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5516 KB Output is correct
3 Correct 1 ms 5468 KB Output is correct
4 Correct 1 ms 5468 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5468 KB Output is correct
7 Correct 1 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 415 ms 59816 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 141 ms 33356 KB Output is correct
12 Correct 37 ms 13120 KB Output is correct
13 Correct 36 ms 14672 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 418 ms 59720 KB Output is correct
17 Correct 1 ms 5468 KB Output is correct
18 Correct 1 ms 5468 KB Output is correct
19 Incorrect 2 ms 5468 KB a[4] = 0 is not an odd integer
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5516 KB Output is correct
3 Correct 1 ms 5468 KB Output is correct
4 Correct 1 ms 5468 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5468 KB Output is correct
7 Correct 1 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 415 ms 59816 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 141 ms 33356 KB Output is correct
12 Correct 37 ms 13120 KB Output is correct
13 Correct 36 ms 14672 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 418 ms 59720 KB Output is correct
17 Correct 1 ms 5468 KB Output is correct
18 Correct 1 ms 5468 KB Output is correct
19 Incorrect 2 ms 5468 KB a[4] = 0 is not an odd integer
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5516 KB Output is correct
3 Correct 1 ms 5468 KB Output is correct
4 Correct 1 ms 5468 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5468 KB Output is correct
7 Correct 1 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 415 ms 59816 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 141 ms 33356 KB Output is correct
12 Correct 37 ms 13120 KB Output is correct
13 Correct 36 ms 14672 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 418 ms 59720 KB Output is correct
17 Correct 1 ms 5468 KB Output is correct
18 Correct 2 ms 5468 KB Output is correct
19 Correct 2 ms 5468 KB Output is correct
20 Correct 774 ms 86740 KB Output is correct
21 Correct 846 ms 93004 KB Output is correct
22 Correct 862 ms 86780 KB Output is correct
23 Correct 749 ms 98392 KB Output is correct
24 Correct 473 ms 52704 KB Output is correct
25 Correct 357 ms 49008 KB Output is correct
26 Correct 388 ms 48756 KB Output is correct
27 Correct 1032 ms 114740 KB Output is correct
28 Correct 1014 ms 114516 KB Output is correct
29 Correct 928 ms 112388 KB Output is correct
30 Correct 926 ms 112436 KB Output is correct
31 Correct 2 ms 5468 KB Output is correct
32 Correct 41 ms 11828 KB Output is correct
33 Correct 111 ms 28968 KB Output is correct
34 Correct 802 ms 93048 KB Output is correct
35 Correct 10 ms 7516 KB Output is correct
36 Correct 57 ms 15212 KB Output is correct
37 Correct 140 ms 24936 KB Output is correct
38 Correct 259 ms 39368 KB Output is correct
39 Correct 420 ms 52256 KB Output is correct
40 Correct 585 ms 65120 KB Output is correct
41 Correct 736 ms 77664 KB Output is correct
42 Correct 962 ms 90740 KB Output is correct
43 Correct 1 ms 5468 KB Output is correct
44 Correct 1 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 1 ms 5468 KB Output is correct
48 Correct 2 ms 5468 KB Output is correct
49 Correct 1 ms 5468 KB Output is correct
50 Correct 1 ms 5468 KB Output is correct
51 Correct 1 ms 5468 KB Output is correct
52 Correct 1 ms 5468 KB Output is correct
53 Correct 1 ms 5468 KB Output is correct
54 Correct 3 ms 5724 KB Output is correct
55 Correct 3 ms 5960 KB Output is correct
56 Correct 371 ms 51928 KB Output is correct
57 Correct 607 ms 72980 KB Output is correct
58 Correct 670 ms 73156 KB Output is correct
59 Correct 1 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 990 ms 115124 KB Output is correct
63 Correct 1004 ms 115124 KB Output is correct
64 Correct 1000 ms 114492 KB Output is correct
65 Correct 4 ms 6236 KB Output is correct
66 Correct 8 ms 7004 KB Output is correct
67 Correct 369 ms 51252 KB Output is correct
68 Correct 660 ms 74128 KB Output is correct
69 Correct 999 ms 97000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5516 KB Output is correct
3 Correct 1 ms 5468 KB Output is correct
4 Correct 1 ms 5468 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5468 KB Output is correct
7 Correct 1 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 415 ms 59816 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 141 ms 33356 KB Output is correct
12 Correct 37 ms 13120 KB Output is correct
13 Correct 36 ms 14672 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 418 ms 59720 KB Output is correct
17 Correct 897 ms 114888 KB Output is correct
18 Correct 872 ms 114600 KB Output is correct
19 Correct 785 ms 90040 KB Output is correct
20 Correct 853 ms 89984 KB Output is correct
21 Correct 774 ms 90756 KB Output is correct
22 Correct 2 ms 5464 KB Output is correct
23 Correct 85 ms 19044 KB Output is correct
24 Correct 20 ms 9056 KB Output is correct
25 Correct 83 ms 18880 KB Output is correct
26 Correct 168 ms 28228 KB Output is correct
27 Correct 340 ms 47944 KB Output is correct
28 Correct 485 ms 58696 KB Output is correct
29 Correct 603 ms 69304 KB Output is correct
30 Correct 763 ms 79908 KB Output is correct
31 Correct 922 ms 90676 KB Output is correct
32 Correct 907 ms 100680 KB Output is correct
33 Correct 1020 ms 115024 KB Output is correct
34 Correct 5 ms 6492 KB Output is correct
35 Correct 9 ms 7260 KB Output is correct
36 Correct 377 ms 51624 KB Output is correct
37 Correct 648 ms 75072 KB Output is correct
38 Correct 979 ms 98568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5516 KB Output is correct
3 Correct 1 ms 5468 KB Output is correct
4 Correct 1 ms 5468 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5468 KB Output is correct
7 Correct 1 ms 5468 KB Output is correct
8 Correct 1 ms 5468 KB Output is correct
9 Correct 415 ms 59816 KB Output is correct
10 Correct 24 ms 10588 KB Output is correct
11 Correct 141 ms 33356 KB Output is correct
12 Correct 37 ms 13120 KB Output is correct
13 Correct 36 ms 14672 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 418 ms 59720 KB Output is correct
17 Correct 1 ms 5468 KB Output is correct
18 Correct 1 ms 5468 KB Output is correct
19 Incorrect 2 ms 5468 KB a[4] = 0 is not an odd integer
20 Halted 0 ms 0 KB -