#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int n;
map<pii, int> field;
vector<int> x, y, used;
vector<pii> e;
void dfs(int v, int p) {
if (used[v])
return;
if (p != -1)
e.emplace_back(v, p);
used[v] = 1;
int vx = x[v], vy = y[v];
pii t[4] = {{vx + 2, vy}, {vx - 2, vy}, {vx, vy + 2}, {vx, vy - 2}};
for (int i = 0; i < 4; i++)
if (field.count(t[i]))
dfs(field[t[i]], v);
}
int construct_roads(std::vector<int> X, std::vector<int> Y) {
n = X.size(), x = X, y = Y;
for (int i = 0; i < n; i++)
field[{x[i], y[i]}] = i;
used.resize(n, 0);
dfs(0, -1);
if (count(used.begin(), used.end(), 0))
return 0;
vector<int> us, vs;
set<pii> loc;
for (int i = 0; i < e.size(); i++) {
us.push_back(e[i].first), vs.push_back(e[i].second);
pii p = e[i];
pii mid = {(x[p.first] + x[p.second]) / 2, (y[p.first] + y[p.second]) / 2};
field[mid] = i;
if (x[p.first] == x[p.second]) {
loc.insert({mid.first-1, mid.second});
loc.insert({mid.first+1, mid.second});
} else {
loc.insert({mid.first, mid.second+1});
loc.insert({mid.first, mid.second-1});
}
}
vector<int> a(e.size(), -1), b(e.size());
for (pii p : loc) {
pii p1 = p, p2 = p;
if ((p.first / 2 + p.second / 2) % 2)
p1.first++, p2.first--;
else
p1.second++, p2.second--;
if (field.count(p1)) {
a[field[p1]] = p.first, b[field[p1]] = p.second;
field.erase(p1);
} else if (field.count(p2)) {
a[field[p2]] = p.first, b[field[p2]] = p.second;
field.erase(p2);
}
}
if (count(a.begin(), a.end(), -1))
return 0;
build(us, vs, a, b);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 0; i < e.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
285 ms |
45484 KB |
Output is correct |
10 |
Correct |
21 ms |
4872 KB |
Output is correct |
11 |
Correct |
147 ms |
25092 KB |
Output is correct |
12 |
Correct |
34 ms |
7220 KB |
Output is correct |
13 |
Correct |
36 ms |
9232 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
263 ms |
39708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
285 ms |
45484 KB |
Output is correct |
10 |
Correct |
21 ms |
4872 KB |
Output is correct |
11 |
Correct |
147 ms |
25092 KB |
Output is correct |
12 |
Correct |
34 ms |
7220 KB |
Output is correct |
13 |
Correct |
36 ms |
9232 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
263 ms |
39708 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
285 ms |
45484 KB |
Output is correct |
10 |
Correct |
21 ms |
4872 KB |
Output is correct |
11 |
Correct |
147 ms |
25092 KB |
Output is correct |
12 |
Correct |
34 ms |
7220 KB |
Output is correct |
13 |
Correct |
36 ms |
9232 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
263 ms |
39708 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
285 ms |
45484 KB |
Output is correct |
10 |
Correct |
21 ms |
4872 KB |
Output is correct |
11 |
Correct |
147 ms |
25092 KB |
Output is correct |
12 |
Correct |
34 ms |
7220 KB |
Output is correct |
13 |
Correct |
36 ms |
9232 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
263 ms |
39708 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
0 ms |
300 KB |
Output is correct |
20 |
Correct |
534 ms |
84752 KB |
Output is correct |
21 |
Correct |
580 ms |
79140 KB |
Output is correct |
22 |
Correct |
576 ms |
75936 KB |
Output is correct |
23 |
Correct |
549 ms |
71260 KB |
Output is correct |
24 |
Correct |
143 ms |
19912 KB |
Output is correct |
25 |
Correct |
148 ms |
19932 KB |
Output is correct |
26 |
Correct |
175 ms |
19868 KB |
Output is correct |
27 |
Correct |
528 ms |
65080 KB |
Output is correct |
28 |
Correct |
553 ms |
65116 KB |
Output is correct |
29 |
Correct |
722 ms |
64932 KB |
Output is correct |
30 |
Correct |
728 ms |
65132 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
35 ms |
5452 KB |
Output is correct |
33 |
Correct |
53 ms |
10548 KB |
Output is correct |
34 |
Correct |
564 ms |
80400 KB |
Output is correct |
35 |
Correct |
7 ms |
1364 KB |
Output is correct |
36 |
Correct |
31 ms |
5544 KB |
Output is correct |
37 |
Correct |
65 ms |
10700 KB |
Output is correct |
38 |
Correct |
226 ms |
24092 KB |
Output is correct |
39 |
Correct |
324 ms |
32620 KB |
Output is correct |
40 |
Correct |
440 ms |
41608 KB |
Output is correct |
41 |
Correct |
515 ms |
50336 KB |
Output is correct |
42 |
Correct |
629 ms |
59228 KB |
Output is correct |
43 |
Correct |
1 ms |
296 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
300 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
2 ms |
596 KB |
Output is correct |
55 |
Correct |
2 ms |
564 KB |
Output is correct |
56 |
Correct |
275 ms |
38264 KB |
Output is correct |
57 |
Correct |
418 ms |
56276 KB |
Output is correct |
58 |
Correct |
439 ms |
55456 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
300 KB |
Output is correct |
61 |
Correct |
1 ms |
212 KB |
Output is correct |
62 |
Correct |
596 ms |
84944 KB |
Output is correct |
63 |
Correct |
581 ms |
85376 KB |
Output is correct |
64 |
Correct |
591 ms |
88084 KB |
Output is correct |
65 |
Correct |
3 ms |
724 KB |
Output is correct |
66 |
Correct |
5 ms |
1236 KB |
Output is correct |
67 |
Correct |
298 ms |
33972 KB |
Output is correct |
68 |
Correct |
448 ms |
54736 KB |
Output is correct |
69 |
Correct |
661 ms |
68336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
285 ms |
45484 KB |
Output is correct |
10 |
Correct |
21 ms |
4872 KB |
Output is correct |
11 |
Correct |
147 ms |
25092 KB |
Output is correct |
12 |
Correct |
34 ms |
7220 KB |
Output is correct |
13 |
Correct |
36 ms |
9232 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
263 ms |
39708 KB |
Output is correct |
17 |
Correct |
624 ms |
93876 KB |
Output is correct |
18 |
Correct |
610 ms |
82944 KB |
Output is correct |
19 |
Correct |
589 ms |
85124 KB |
Output is correct |
20 |
Correct |
731 ms |
73216 KB |
Output is correct |
21 |
Correct |
576 ms |
65440 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
75 ms |
10568 KB |
Output is correct |
24 |
Correct |
16 ms |
3028 KB |
Output is correct |
25 |
Correct |
47 ms |
8384 KB |
Output is correct |
26 |
Correct |
82 ms |
13408 KB |
Output is correct |
27 |
Correct |
304 ms |
36212 KB |
Output is correct |
28 |
Correct |
399 ms |
45160 KB |
Output is correct |
29 |
Correct |
488 ms |
54668 KB |
Output is correct |
30 |
Correct |
584 ms |
63172 KB |
Output is correct |
31 |
Correct |
701 ms |
72096 KB |
Output is correct |
32 |
Correct |
672 ms |
81176 KB |
Output is correct |
33 |
Correct |
604 ms |
93092 KB |
Output is correct |
34 |
Correct |
4 ms |
980 KB |
Output is correct |
35 |
Correct |
6 ms |
1492 KB |
Output is correct |
36 |
Correct |
286 ms |
36592 KB |
Output is correct |
37 |
Correct |
460 ms |
56212 KB |
Output is correct |
38 |
Correct |
648 ms |
75088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
285 ms |
45484 KB |
Output is correct |
10 |
Correct |
21 ms |
4872 KB |
Output is correct |
11 |
Correct |
147 ms |
25092 KB |
Output is correct |
12 |
Correct |
34 ms |
7220 KB |
Output is correct |
13 |
Correct |
36 ms |
9232 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
263 ms |
39708 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |