Submission #925407

# Submission time Handle Problem Language Result Execution time Memory
925407 2024-02-11T14:52:27 Z Itamar Fountain Parks (IOI21_parks) C++17
45 / 100
1057 ms 115332 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;
      |      ~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5512 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 528 ms 59980 KB Output is correct
10 Correct 24 ms 10700 KB Output is correct
11 Correct 154 ms 33384 KB Output is correct
12 Correct 37 ms 13324 KB Output is correct
13 Correct 32 ms 14680 KB Output is correct
14 Correct 2 ms 5880 KB Output is correct
15 Correct 4 ms 5724 KB Output is correct
16 Correct 456 ms 59764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5512 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 528 ms 59980 KB Output is correct
10 Correct 24 ms 10700 KB Output is correct
11 Correct 154 ms 33384 KB Output is correct
12 Correct 37 ms 13324 KB Output is correct
13 Correct 32 ms 14680 KB Output is correct
14 Correct 2 ms 5880 KB Output is correct
15 Correct 4 ms 5724 KB Output is correct
16 Correct 456 ms 59764 KB Output is correct
17 Correct 2 ms 5464 KB Output is correct
18 Correct 2 ms 5468 KB Output is correct
19 Correct 2 ms 5468 KB Output is correct
20 Correct 2 ms 5464 KB Output is correct
21 Correct 1 ms 5468 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Incorrect 966 ms 89008 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 2 ms 5468 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5512 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 528 ms 59980 KB Output is correct
10 Correct 24 ms 10700 KB Output is correct
11 Correct 154 ms 33384 KB Output is correct
12 Correct 37 ms 13324 KB Output is correct
13 Correct 32 ms 14680 KB Output is correct
14 Correct 2 ms 5880 KB Output is correct
15 Correct 4 ms 5724 KB Output is correct
16 Correct 456 ms 59764 KB Output is correct
17 Correct 2 ms 5464 KB Output is correct
18 Correct 2 ms 5468 KB Output is correct
19 Correct 2 ms 5468 KB Output is correct
20 Correct 2 ms 5464 KB Output is correct
21 Correct 1 ms 5468 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Incorrect 966 ms 89008 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 2 ms 5468 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5512 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 528 ms 59980 KB Output is correct
10 Correct 24 ms 10700 KB Output is correct
11 Correct 154 ms 33384 KB Output is correct
12 Correct 37 ms 13324 KB Output is correct
13 Correct 32 ms 14680 KB Output is correct
14 Correct 2 ms 5880 KB Output is correct
15 Correct 4 ms 5724 KB Output is correct
16 Correct 456 ms 59764 KB Output is correct
17 Correct 2 ms 5464 KB Output is correct
18 Correct 1 ms 5468 KB Output is correct
19 Correct 1 ms 5468 KB Output is correct
20 Correct 739 ms 86480 KB Output is correct
21 Correct 886 ms 93144 KB Output is correct
22 Correct 849 ms 86776 KB Output is correct
23 Correct 748 ms 98228 KB Output is correct
24 Correct 443 ms 52724 KB Output is correct
25 Correct 413 ms 48784 KB Output is correct
26 Correct 373 ms 48708 KB Output is correct
27 Correct 1006 ms 112152 KB Output is correct
28 Correct 1004 ms 112360 KB Output is correct
29 Correct 946 ms 114212 KB Output is correct
30 Correct 982 ms 114720 KB Output is correct
31 Correct 1 ms 5468 KB Output is correct
32 Correct 40 ms 11804 KB Output is correct
33 Correct 119 ms 28752 KB Output is correct
34 Correct 887 ms 93048 KB Output is correct
35 Correct 13 ms 7516 KB Output is correct
36 Correct 64 ms 15232 KB Output is correct
37 Correct 162 ms 24960 KB Output is correct
38 Correct 253 ms 39268 KB Output is correct
39 Correct 411 ms 52072 KB Output is correct
40 Correct 609 ms 65376 KB Output is correct
41 Correct 747 ms 77792 KB Output is correct
42 Correct 1004 ms 90724 KB Output is correct
43 Correct 1 ms 5468 KB Output is correct
44 Correct 2 ms 5468 KB Output is correct
45 Correct 1 ms 5468 KB Output is correct
46 Correct 2 ms 5468 KB Output is correct
47 Correct 1 ms 5468 KB Output is correct
48 Correct 1 ms 5468 KB Output is correct
49 Correct 2 ms 5620 KB Output is correct
50 Correct 1 ms 5468 KB Output is correct
51 Correct 1 ms 5468 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 5928 KB Output is correct
56 Correct 395 ms 52092 KB Output is correct
57 Correct 686 ms 73332 KB Output is correct
58 Correct 732 ms 73304 KB Output is correct
59 Correct 2 ms 5464 KB Output is correct
60 Correct 2 ms 5468 KB Output is correct
61 Correct 1 ms 5468 KB Output is correct
62 Correct 1057 ms 114756 KB Output is correct
63 Correct 1018 ms 115332 KB Output is correct
64 Correct 1039 ms 114328 KB Output is correct
65 Correct 4 ms 6488 KB Output is correct
66 Correct 8 ms 7004 KB Output is correct
67 Correct 414 ms 51136 KB Output is correct
68 Correct 669 ms 74684 KB Output is correct
69 Correct 984 ms 97460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5512 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 528 ms 59980 KB Output is correct
10 Correct 24 ms 10700 KB Output is correct
11 Correct 154 ms 33384 KB Output is correct
12 Correct 37 ms 13324 KB Output is correct
13 Correct 32 ms 14680 KB Output is correct
14 Correct 2 ms 5880 KB Output is correct
15 Correct 4 ms 5724 KB Output is correct
16 Correct 456 ms 59764 KB Output is correct
17 Correct 896 ms 114680 KB Output is correct
18 Correct 955 ms 114608 KB Output is correct
19 Correct 869 ms 89876 KB Output is correct
20 Correct 895 ms 90164 KB Output is correct
21 Correct 765 ms 90692 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Correct 91 ms 18928 KB Output is correct
24 Correct 21 ms 9320 KB Output is correct
25 Correct 89 ms 18844 KB Output is correct
26 Correct 161 ms 27968 KB Output is correct
27 Correct 374 ms 47928 KB Output is correct
28 Correct 512 ms 58508 KB Output is correct
29 Correct 597 ms 69356 KB Output is correct
30 Correct 778 ms 80048 KB Output is correct
31 Correct 961 ms 90860 KB Output is correct
32 Correct 905 ms 97384 KB Output is correct
33 Correct 1034 ms 114968 KB Output is correct
34 Correct 5 ms 6492 KB Output is correct
35 Correct 9 ms 7260 KB Output is correct
36 Correct 409 ms 50404 KB Output is correct
37 Correct 667 ms 73376 KB Output is correct
38 Correct 1030 ms 96060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 2 ms 5464 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5512 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 528 ms 59980 KB Output is correct
10 Correct 24 ms 10700 KB Output is correct
11 Correct 154 ms 33384 KB Output is correct
12 Correct 37 ms 13324 KB Output is correct
13 Correct 32 ms 14680 KB Output is correct
14 Correct 2 ms 5880 KB Output is correct
15 Correct 4 ms 5724 KB Output is correct
16 Correct 456 ms 59764 KB Output is correct
17 Correct 2 ms 5464 KB Output is correct
18 Correct 2 ms 5468 KB Output is correct
19 Correct 2 ms 5468 KB Output is correct
20 Correct 2 ms 5464 KB Output is correct
21 Correct 1 ms 5468 KB Output is correct
22 Correct 1 ms 5468 KB Output is correct
23 Incorrect 966 ms 89008 KB a[96849] = 0 is not an odd integer
24 Halted 0 ms 0 KB -