Submission #925408

# Submission time Handle Problem Language Result Execution time Memory
925408 2024-02-11T14:53:27 Z Itamar Fountain Parks (IOI21_parks) C++17
45 / 100
1059 ms 115276 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 : ed1)ed.push_back(p); for (pi p : ed2)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 1 ms 5468 KB Output is correct
2 Correct 1 ms 5468 KB Output is correct
3 Correct 1 ms 5496 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 419 ms 59744 KB Output is correct
10 Correct 24 ms 10576 KB Output is correct
11 Correct 139 ms 33580 KB Output is correct
12 Correct 36 ms 13136 KB Output is correct
13 Correct 31 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 414 ms 59608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 1 ms 5468 KB Output is correct
3 Correct 1 ms 5496 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 419 ms 59744 KB Output is correct
10 Correct 24 ms 10576 KB Output is correct
11 Correct 139 ms 33580 KB Output is correct
12 Correct 36 ms 13136 KB Output is correct
13 Correct 31 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 414 ms 59608 KB Output is correct
17 Correct 1 ms 5464 KB Output is correct
18 Correct 1 ms 5468 KB Output is correct
19 Correct 2 ms 5520 KB Output is correct
20 Correct 1 ms 5720 KB Output is correct
21 Correct 1 ms 5468 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Incorrect 858 ms 88580 KB a[96849] = 0 is not an odd integer
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 1 ms 5468 KB Output is correct
3 Correct 1 ms 5496 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 419 ms 59744 KB Output is correct
10 Correct 24 ms 10576 KB Output is correct
11 Correct 139 ms 33580 KB Output is correct
12 Correct 36 ms 13136 KB Output is correct
13 Correct 31 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 414 ms 59608 KB Output is correct
17 Correct 1 ms 5464 KB Output is correct
18 Correct 1 ms 5468 KB Output is correct
19 Correct 2 ms 5520 KB Output is correct
20 Correct 1 ms 5720 KB Output is correct
21 Correct 1 ms 5468 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Incorrect 858 ms 88580 KB a[96849] = 0 is not an odd integer
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 1 ms 5468 KB Output is correct
3 Correct 1 ms 5496 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 419 ms 59744 KB Output is correct
10 Correct 24 ms 10576 KB Output is correct
11 Correct 139 ms 33580 KB Output is correct
12 Correct 36 ms 13136 KB Output is correct
13 Correct 31 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 414 ms 59608 KB Output is correct
17 Correct 1 ms 5468 KB Output is correct
18 Correct 2 ms 5468 KB Output is correct
19 Correct 1 ms 5468 KB Output is correct
20 Correct 785 ms 86744 KB Output is correct
21 Correct 873 ms 93332 KB Output is correct
22 Correct 742 ms 86824 KB Output is correct
23 Correct 740 ms 98236 KB Output is correct
24 Correct 389 ms 52816 KB Output is correct
25 Correct 367 ms 48960 KB Output is correct
26 Correct 365 ms 48844 KB Output is correct
27 Correct 983 ms 112304 KB Output is correct
28 Correct 988 ms 112528 KB Output is correct
29 Correct 937 ms 114296 KB Output is correct
30 Correct 966 ms 114736 KB Output is correct
31 Correct 1 ms 5468 KB Output is correct
32 Correct 37 ms 11696 KB Output is correct
33 Correct 109 ms 28976 KB Output is correct
34 Correct 762 ms 92852 KB Output is correct
35 Correct 10 ms 7516 KB Output is correct
36 Correct 57 ms 15064 KB Output is correct
37 Correct 129 ms 24968 KB Output is correct
38 Correct 301 ms 39268 KB Output is correct
39 Correct 415 ms 52160 KB Output is correct
40 Correct 581 ms 65288 KB Output is correct
41 Correct 742 ms 77816 KB Output is correct
42 Correct 962 ms 90808 KB Output is correct
43 Correct 2 ms 5468 KB Output is correct
44 Correct 1 ms 5468 KB Output is correct
45 Correct 2 ms 5468 KB Output is correct
46 Correct 1 ms 5520 KB Output is correct
47 Correct 1 ms 5464 KB Output is correct
48 Correct 1 ms 5468 KB Output is correct
49 Correct 1 ms 5492 KB Output is correct
50 Correct 1 ms 5464 KB Output is correct
51 Correct 2 ms 5876 KB Output is correct
52 Correct 2 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 4 ms 5980 KB Output is correct
56 Correct 379 ms 51976 KB Output is correct
57 Correct 635 ms 73312 KB Output is correct
58 Correct 657 ms 73208 KB Output is correct
59 Correct 1 ms 5464 KB Output is correct
60 Correct 1 ms 5468 KB Output is correct
61 Correct 2 ms 5468 KB Output is correct
62 Correct 1024 ms 114784 KB Output is correct
63 Correct 1059 ms 115276 KB Output is correct
64 Correct 1025 ms 114572 KB Output is correct
65 Correct 4 ms 6236 KB Output is correct
66 Correct 8 ms 7184 KB Output is correct
67 Correct 385 ms 51144 KB Output is correct
68 Correct 646 ms 74236 KB Output is correct
69 Correct 969 ms 97716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 1 ms 5468 KB Output is correct
3 Correct 1 ms 5496 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 419 ms 59744 KB Output is correct
10 Correct 24 ms 10576 KB Output is correct
11 Correct 139 ms 33580 KB Output is correct
12 Correct 36 ms 13136 KB Output is correct
13 Correct 31 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 414 ms 59608 KB Output is correct
17 Correct 914 ms 114640 KB Output is correct
18 Correct 905 ms 114756 KB Output is correct
19 Correct 812 ms 89996 KB Output is correct
20 Correct 901 ms 90056 KB Output is correct
21 Correct 827 ms 90552 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Correct 87 ms 18940 KB Output is correct
24 Correct 21 ms 9316 KB Output is correct
25 Correct 92 ms 19168 KB Output is correct
26 Correct 166 ms 27836 KB Output is correct
27 Correct 387 ms 47740 KB Output is correct
28 Correct 462 ms 58652 KB Output is correct
29 Correct 613 ms 69220 KB Output is correct
30 Correct 736 ms 80048 KB Output is correct
31 Correct 932 ms 90892 KB Output is correct
32 Correct 956 ms 97372 KB Output is correct
33 Correct 1014 ms 115016 KB Output is correct
34 Correct 5 ms 6488 KB Output is correct
35 Correct 9 ms 7260 KB Output is correct
36 Correct 389 ms 50572 KB Output is correct
37 Correct 716 ms 73368 KB Output is correct
38 Correct 982 ms 96256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 1 ms 5468 KB Output is correct
3 Correct 1 ms 5496 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 419 ms 59744 KB Output is correct
10 Correct 24 ms 10576 KB Output is correct
11 Correct 139 ms 33580 KB Output is correct
12 Correct 36 ms 13136 KB Output is correct
13 Correct 31 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 414 ms 59608 KB Output is correct
17 Correct 1 ms 5464 KB Output is correct
18 Correct 1 ms 5468 KB Output is correct
19 Correct 2 ms 5520 KB Output is correct
20 Correct 1 ms 5720 KB Output is correct
21 Correct 1 ms 5468 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Incorrect 858 ms 88580 KB a[96849] = 0 is not an odd integer
24 Halted 0 ms 0 KB -