Submission #435681

# Submission time Handle Problem Language Result Execution time Memory
435681 2021-06-23T15:01:28 Z BERNARB01 Fountain Parks (IOI21_parks) C++17
15 / 100
321 ms 43336 KB
#include "parks.h"
#include <bits/stdc++.h>

using namespace std;

int construct_roads(vector<int> x, vector<int> y) {
	if (x.size() == 1) {
		build({}, {}, {}, {});
		return 1;
	}
	int n = x.size();
	vector<pair<int, int>> p2, p4;
	for (int i = 0; i < n; i++) {
		if (x[i] == 2) {
			p2.emplace_back(y[i], i);
		} else if (x[i] == 4) {
			p4.emplace_back(y[i], i);
		}
	}
	sort(p2.begin(), p2.end());
	sort(p4.begin(), p4.end());
	vector<int> u, v, a, b;
	for (int j = 1; j < (int) p2.size(); j++) {
		int i = p2[j].second;
		int k = p2[j - 1].second;
		if (y[i] - y[k] > 2) {
			continue;
		}
		u.push_back(k);
		v.push_back(i);
		a.push_back(1);
		b.push_back(y[i] - 1);
	}
	for (int j = 1; j < (int) p4.size(); j++) {
		int i = p4[j].second;
		int k = p4[j - 1].second;
		if (y[i] - y[k] > 2) {
			continue;
		}
		u.push_back(k);
		v.push_back(i);
		a.push_back(5);
		b.push_back(y[i] - 1);
	}
	for (int i = 0, j = 0; i < (int) p2.size(); i++) {
		while (j < (int) p4.size() && p4[j].first < p2[i].first) {
			j++;
		}
		if (j >= (int) p4.size()) {
			break;
		}
		if (p2[i].first == p4[j].first) {
			int ii = p2[i].second;
			int jj = p4[j].second;
			u.push_back(ii);
			v.push_back(jj);
			a.push_back(3);
			b.push_back(y[ii] - 1);
		}
	}
	auto dist = [&](int i, int j) {
		return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
	};
	vector<vector<int>> g(n);
	for (int i = 0; i < (int) u.size(); i++) {
		if (dist(u[i], v[i]) > 4) {
			return 0;
		}
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	vector<int> vis(n, 0);
	function<void(int)> dfs = [&](int uu) {
		if (vis[uu]) {
			return;
		}
		vis[uu] = 1;
		for (int vv : g[uu]) {
			dfs(vv);
		}
	};
	dfs(0);
	if (accumulate(vis.begin(), vis.end(), 0) == n) {
		build(u, v, a, b);
		return 1;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 132 ms 19008 KB Output is correct
10 Correct 8 ms 2252 KB Output is correct
11 Correct 43 ms 10700 KB Output is correct
12 Correct 12 ms 3148 KB Output is correct
13 Correct 19 ms 6596 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 102 ms 16552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 132 ms 19008 KB Output is correct
10 Correct 8 ms 2252 KB Output is correct
11 Correct 43 ms 10700 KB Output is correct
12 Correct 12 ms 3148 KB Output is correct
13 Correct 19 ms 6596 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 102 ms 16552 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 314 ms 43336 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 716 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 100 ms 17592 KB Output is correct
29 Correct 175 ms 26084 KB Output is correct
30 Correct 237 ms 34736 KB Output is correct
31 Correct 321 ms 43272 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 116 ms 17136 KB Output is correct
46 Correct 174 ms 25416 KB Output is correct
47 Correct 165 ms 25088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 132 ms 19008 KB Output is correct
10 Correct 8 ms 2252 KB Output is correct
11 Correct 43 ms 10700 KB Output is correct
12 Correct 12 ms 3148 KB Output is correct
13 Correct 19 ms 6596 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 102 ms 16552 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 314 ms 43336 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 716 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 100 ms 17592 KB Output is correct
29 Correct 175 ms 26084 KB Output is correct
30 Correct 237 ms 34736 KB Output is correct
31 Correct 321 ms 43272 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 116 ms 17136 KB Output is correct
46 Correct 174 ms 25416 KB Output is correct
47 Correct 165 ms 25088 KB Output is correct
48 Incorrect 1 ms 204 KB Solution announced impossible, but it is possible.
49 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 132 ms 19008 KB Output is correct
10 Correct 8 ms 2252 KB Output is correct
11 Correct 43 ms 10700 KB Output is correct
12 Correct 12 ms 3148 KB Output is correct
13 Correct 19 ms 6596 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 102 ms 16552 KB Output is correct
17 Incorrect 1 ms 204 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 132 ms 19008 KB Output is correct
10 Correct 8 ms 2252 KB Output is correct
11 Correct 43 ms 10700 KB Output is correct
12 Correct 12 ms 3148 KB Output is correct
13 Correct 19 ms 6596 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 102 ms 16552 KB Output is correct
17 Incorrect 71 ms 11704 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 132 ms 19008 KB Output is correct
10 Correct 8 ms 2252 KB Output is correct
11 Correct 43 ms 10700 KB Output is correct
12 Correct 12 ms 3148 KB Output is correct
13 Correct 19 ms 6596 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 102 ms 16552 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 314 ms 43336 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 716 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 100 ms 17592 KB Output is correct
29 Correct 175 ms 26084 KB Output is correct
30 Correct 237 ms 34736 KB Output is correct
31 Correct 321 ms 43272 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 116 ms 17136 KB Output is correct
46 Correct 174 ms 25416 KB Output is correct
47 Correct 165 ms 25088 KB Output is correct
48 Incorrect 1 ms 204 KB Solution announced impossible, but it is possible.
49 Halted 0 ms 0 KB -