#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3e2;
#define all(x) (x).begin(), (x).end()
int p[N];
int find(int x){
return (x == p[x] ? x : p[x] = find(p[x]));
}
bool unite(int x, int y){
x = find(x);
y = find(y);
if (x == y) return false;
if (rand() & 1) swap(x, y);
p[x] = y;
return true;
}
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
if (n == 1) {
build({}, {}, {}, {});
return 1;
}
vector<int> perm(n);
iota(all(perm), 0);
sort(all(perm), [&](int i, int j){
return x[i] < x[j] || x[i] == x[j] && y[i] < y[j];
});
iota(p, p + n, 0);
map<pair<int, int>, int> id;
for (int i = 0; i < n; i++){
id[{x[i], y[i]}] = i;
}
vector<int> U, V, A(n - 1), B(n - 1);
vector<int> dx = {2, 0};
vector<int> dy = {0, 2};
for (int it = 0; it < dx.size(); it++){
for (int i = 0; i < n; i++){
int X = x[i] + dx[it], Y = y[i] + dy[it];
if (id.find({X, Y}) != id.end()){
int j = id[{X, Y}];
if (!unite(i, j)) continue;
U.push_back(i);
V.push_back(j);
}
}
}
if (U.size() != n - 1) return 0;
for (int it = 0; it < n - 1; it++){
int i = U[it], j = V[it];
if (x[i] == x[j]){
B[it] = (y[i] + y[j]) / 2;
if (x[i] == 2) A[it] = 1;
if (x[i] == 6) A[it] = 7;
if (x[i] == 4) B[it] = -1;
} else {
A[it] = (x[i] + x[j]) / 2;
B[it] = y[i] + (A[it] == 3 ? -1 : 1);
}
}
set<pair<int, int>> points;
for (int it = 0; it < n - 1; it++){
if (B[it] != -1) points.insert(make_pair(A[it], B[it]));
}
for (int it = 0; it < n - 1; it++){
int i = U[it], j = V[it];
if (x[i] == x[j] && x[i] == 4){
int Y = (y[i] + y[j]) / 2;
if (points.find({3, Y}) == points.end()) A[it] = 3;
else A[it] = 5;
B[it] = Y;
}
}
build(U, V, A, B);
return 1;
}
Compilation message
parks.cpp: In lambda function:
parks.cpp:35:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
35 | return x[i] < x[j] || x[i] == x[j] && y[i] < y[j];
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:50:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int it = 0; it < dx.size(); it++){
| ~~~^~~~~~~~~~~
parks.cpp:62:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
62 | if (U.size() != n - 1) return 0;
| ~~~~~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
168 ms |
18248 KB |
Output is correct |
10 |
Correct |
10 ms |
2180 KB |
Output is correct |
11 |
Correct |
64 ms |
9912 KB |
Output is correct |
12 |
Correct |
16 ms |
3276 KB |
Output is correct |
13 |
Correct |
32 ms |
5036 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
167 ms |
18292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
168 ms |
18248 KB |
Output is correct |
10 |
Correct |
10 ms |
2180 KB |
Output is correct |
11 |
Correct |
64 ms |
9912 KB |
Output is correct |
12 |
Correct |
16 ms |
3276 KB |
Output is correct |
13 |
Correct |
32 ms |
5036 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
167 ms |
18292 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
483 ms |
33928 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
3 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
588 KB |
Output is correct |
27 |
Correct |
4 ms |
716 KB |
Output is correct |
28 |
Correct |
138 ms |
13776 KB |
Output is correct |
29 |
Correct |
231 ms |
20436 KB |
Output is correct |
30 |
Correct |
350 ms |
27364 KB |
Output is correct |
31 |
Correct |
488 ms |
34096 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
0 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 |
178 ms |
16660 KB |
Output is correct |
46 |
Correct |
296 ms |
23944 KB |
Output is correct |
47 |
Correct |
309 ms |
24020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
168 ms |
18248 KB |
Output is correct |
10 |
Correct |
10 ms |
2180 KB |
Output is correct |
11 |
Correct |
64 ms |
9912 KB |
Output is correct |
12 |
Correct |
16 ms |
3276 KB |
Output is correct |
13 |
Correct |
32 ms |
5036 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
167 ms |
18292 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
483 ms |
33928 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
3 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
588 KB |
Output is correct |
27 |
Correct |
4 ms |
716 KB |
Output is correct |
28 |
Correct |
138 ms |
13776 KB |
Output is correct |
29 |
Correct |
231 ms |
20436 KB |
Output is correct |
30 |
Correct |
350 ms |
27364 KB |
Output is correct |
31 |
Correct |
488 ms |
34096 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
0 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 |
178 ms |
16660 KB |
Output is correct |
46 |
Correct |
296 ms |
23944 KB |
Output is correct |
47 |
Correct |
309 ms |
24020 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
0 ms |
204 KB |
Output is correct |
51 |
Correct |
0 ms |
204 KB |
Output is correct |
52 |
Correct |
1 ms |
204 KB |
Output is correct |
53 |
Correct |
0 ms |
204 KB |
Output is correct |
54 |
Incorrect |
0 ms |
204 KB |
Tree @(5, 5) appears more than once: for edges on positions 2 and 6 |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
168 ms |
18248 KB |
Output is correct |
10 |
Correct |
10 ms |
2180 KB |
Output is correct |
11 |
Correct |
64 ms |
9912 KB |
Output is correct |
12 |
Correct |
16 ms |
3276 KB |
Output is correct |
13 |
Correct |
32 ms |
5036 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
167 ms |
18292 KB |
Output is correct |
17 |
Incorrect |
0 ms |
204 KB |
a[1] = 0 is not an odd integer |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
168 ms |
18248 KB |
Output is correct |
10 |
Correct |
10 ms |
2180 KB |
Output is correct |
11 |
Correct |
64 ms |
9912 KB |
Output is correct |
12 |
Correct |
16 ms |
3276 KB |
Output is correct |
13 |
Correct |
32 ms |
5036 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
167 ms |
18292 KB |
Output is correct |
17 |
Incorrect |
541 ms |
36356 KB |
a[100000] = 0 is not an odd integer |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
168 ms |
18248 KB |
Output is correct |
10 |
Correct |
10 ms |
2180 KB |
Output is correct |
11 |
Correct |
64 ms |
9912 KB |
Output is correct |
12 |
Correct |
16 ms |
3276 KB |
Output is correct |
13 |
Correct |
32 ms |
5036 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
167 ms |
18292 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
483 ms |
33928 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
3 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
588 KB |
Output is correct |
27 |
Correct |
4 ms |
716 KB |
Output is correct |
28 |
Correct |
138 ms |
13776 KB |
Output is correct |
29 |
Correct |
231 ms |
20436 KB |
Output is correct |
30 |
Correct |
350 ms |
27364 KB |
Output is correct |
31 |
Correct |
488 ms |
34096 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
0 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 |
178 ms |
16660 KB |
Output is correct |
46 |
Correct |
296 ms |
23944 KB |
Output is correct |
47 |
Correct |
309 ms |
24020 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
0 ms |
204 KB |
Output is correct |
51 |
Correct |
0 ms |
204 KB |
Output is correct |
52 |
Correct |
1 ms |
204 KB |
Output is correct |
53 |
Correct |
0 ms |
204 KB |
Output is correct |
54 |
Incorrect |
0 ms |
204 KB |
Tree @(5, 5) appears more than once: for edges on positions 2 and 6 |
55 |
Halted |
0 ms |
0 KB |
- |