#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pll;
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define sep ' '
#define debug(x) cerr << #x << ": " << x << endl;
const int MAXN = 1e6 + 10;
const int DX[4] = {-1, 0, 1, 0};
const int DY[4] = {0, -1, 0, 1};
namespace answer {
vector<int> u, v, a, b;
}
vector<pair<pll, int>> edges;
int X[MAXN], Y[MAXN], par[MAXN], n;
map<pll, int> mp;
int find(int v) {
return par[v] == v ? v : par[v] = find(par[v]);
}
inline bool unite(int u_, int v_) {
int u = find(u_), v = find(v_);
if (u == v) return false;
edges.push_back({{u_, v_}, (int)answer::u.size()});
answer::u.push_back(u_);
answer::v.push_back(v_);
par[u] = v;
return true;
}
int construct_roads(vector<int> x_, vector<int> y_) {
n = x_.size();
for (int i = 0; i < n; i++) {
X[i] = x_[i];
Y[i] = y_[i];
mp[pll(X[i], Y[i])] = i;
par[i] = i;
}
int edg = 0;
vector<int> vert_vec;
for (int i = 0; i < n; i++) vert_vec.push_back(i);
sort(all(vert_vec), [] (int i, int j) {
return X[i] + Y[i] < X[j] + Y[j];
});
for (int i = 0; i < 4; i++) {
for (int tv = 0; tv < n; tv++) {
int v = vert_vec[tv];
int ux = X[v] + 2 * DX[i], uy = Y[v] + 2 * DY[i];
auto it = mp.find(pll(ux, uy));
if (it == mp.end()) continue;
int u = it -> second;
edg += unite(u, v);
}
}
if (edg < n - 1) return 0;
sort(all(edges), [] (const pair<pll, int>& a, const pair<pll, int>& b) {
return min(X[a.X.X], X[a.X.Y]) + min(Y[a.X.X], Y[a.X.Y]) < min(X[b.X.X], X[b.X.Y]) + min(Y[b.X.X], Y[b.X.Y]);
});
set<pll> st;
answer::a.resize(n - 1);
answer::b.resize(n - 1);
for (int ti = 0; ti < n - 1; ti++) {
int i = edges[ti].Y;
// cerr << answer::u[i] << sep << answer::v[i] << endl;
if (X[answer::u[i]] == X[answer::v[i]]) {
int tx = X[answer::u[i]] - 1, ty = (Y[answer::u[i]] + Y[answer::v[i]]) / 2;
if (st.find(pll(tx, ty)) == st.end()) {
st.insert(pll(tx, ty));
answer::a[i] = tx;
answer::b[i] = ty;
continue;
}
tx += 2;
if (st.find(pll(tx, ty)) == st.end()) {
st.insert(pll(tx, ty));
answer::a[i] = tx;
answer::b[i] = ty;
continue;
}
return 0;
} else {
int ty = Y[answer::u[i]] - 1, tx = (X[answer::u[i]] + X[answer::v[i]]) / 2;
if (st.find(pll(tx, ty)) == st.end()) {
st.insert(pll(tx, ty));
answer::a[i] = tx;
answer::b[i] = ty;
continue;
}
ty += 2;
if (st.find(pll(tx, ty)) == st.end()) {
st.insert(pll(tx, ty));
answer::a[i] = tx;
answer::b[i] = ty;
continue;
}
return 0;
}
}
build(answer::u, answer::v, answer::a, answer::b);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
22428 KB |
Output is correct |
10 |
Correct |
10 ms |
2644 KB |
Output is correct |
11 |
Correct |
58 ms |
12104 KB |
Output is correct |
12 |
Correct |
15 ms |
3668 KB |
Output is correct |
13 |
Correct |
29 ms |
5964 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
139 ms |
22372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
22428 KB |
Output is correct |
10 |
Correct |
10 ms |
2644 KB |
Output is correct |
11 |
Correct |
58 ms |
12104 KB |
Output is correct |
12 |
Correct |
15 ms |
3668 KB |
Output is correct |
13 |
Correct |
29 ms |
5964 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
139 ms |
22372 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
446 ms |
42956 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
620 KB |
Output is correct |
27 |
Correct |
4 ms |
724 KB |
Output is correct |
28 |
Correct |
218 ms |
17392 KB |
Output is correct |
29 |
Correct |
207 ms |
25812 KB |
Output is correct |
30 |
Correct |
421 ms |
34400 KB |
Output is correct |
31 |
Correct |
486 ms |
42884 KB |
Output is correct |
32 |
Correct |
0 ms |
260 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
3 ms |
596 KB |
Output is correct |
45 |
Correct |
180 ms |
21972 KB |
Output is correct |
46 |
Correct |
294 ms |
31672 KB |
Output is correct |
47 |
Correct |
214 ms |
31732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
22428 KB |
Output is correct |
10 |
Correct |
10 ms |
2644 KB |
Output is correct |
11 |
Correct |
58 ms |
12104 KB |
Output is correct |
12 |
Correct |
15 ms |
3668 KB |
Output is correct |
13 |
Correct |
29 ms |
5964 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
139 ms |
22372 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
446 ms |
42956 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
620 KB |
Output is correct |
27 |
Correct |
4 ms |
724 KB |
Output is correct |
28 |
Correct |
218 ms |
17392 KB |
Output is correct |
29 |
Correct |
207 ms |
25812 KB |
Output is correct |
30 |
Correct |
421 ms |
34400 KB |
Output is correct |
31 |
Correct |
486 ms |
42884 KB |
Output is correct |
32 |
Correct |
0 ms |
260 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
3 ms |
596 KB |
Output is correct |
45 |
Correct |
180 ms |
21972 KB |
Output is correct |
46 |
Correct |
294 ms |
31672 KB |
Output is correct |
47 |
Correct |
214 ms |
31732 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
423 ms |
42424 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
2 ms |
724 KB |
Output is correct |
58 |
Correct |
7 ms |
1620 KB |
Output is correct |
59 |
Correct |
8 ms |
1600 KB |
Output is correct |
60 |
Correct |
177 ms |
22048 KB |
Output is correct |
61 |
Correct |
291 ms |
29620 KB |
Output is correct |
62 |
Correct |
389 ms |
36712 KB |
Output is correct |
63 |
Correct |
382 ms |
44040 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
1 ms |
312 KB |
Output is correct |
66 |
Correct |
1 ms |
312 KB |
Output is correct |
67 |
Correct |
446 ms |
45008 KB |
Output is correct |
68 |
Correct |
416 ms |
45172 KB |
Output is correct |
69 |
Correct |
383 ms |
44284 KB |
Output is correct |
70 |
Correct |
3 ms |
724 KB |
Output is correct |
71 |
Correct |
6 ms |
1328 KB |
Output is correct |
72 |
Incorrect |
105 ms |
14232 KB |
Solution announced impossible, but it is possible. |
73 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
22428 KB |
Output is correct |
10 |
Correct |
10 ms |
2644 KB |
Output is correct |
11 |
Correct |
58 ms |
12104 KB |
Output is correct |
12 |
Correct |
15 ms |
3668 KB |
Output is correct |
13 |
Correct |
29 ms |
5964 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
139 ms |
22372 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
571 ms |
45220 KB |
Output is correct |
21 |
Correct |
449 ms |
45848 KB |
Output is correct |
22 |
Correct |
547 ms |
44696 KB |
Output is correct |
23 |
Correct |
353 ms |
38432 KB |
Output is correct |
24 |
Correct |
297 ms |
21116 KB |
Output is correct |
25 |
Correct |
383 ms |
25924 KB |
Output is correct |
26 |
Correct |
308 ms |
25920 KB |
Output is correct |
27 |
Correct |
497 ms |
43624 KB |
Output is correct |
28 |
Correct |
504 ms |
43752 KB |
Output is correct |
29 |
Correct |
581 ms |
43716 KB |
Output is correct |
30 |
Correct |
549 ms |
43644 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Incorrect |
14 ms |
2260 KB |
Solution announced impossible, but it is possible. |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
22428 KB |
Output is correct |
10 |
Correct |
10 ms |
2644 KB |
Output is correct |
11 |
Correct |
58 ms |
12104 KB |
Output is correct |
12 |
Correct |
15 ms |
3668 KB |
Output is correct |
13 |
Correct |
29 ms |
5964 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
139 ms |
22372 KB |
Output is correct |
17 |
Correct |
427 ms |
45168 KB |
Output is correct |
18 |
Correct |
415 ms |
45028 KB |
Output is correct |
19 |
Incorrect |
370 ms |
28960 KB |
Solution announced impossible, but it is possible. |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
22428 KB |
Output is correct |
10 |
Correct |
10 ms |
2644 KB |
Output is correct |
11 |
Correct |
58 ms |
12104 KB |
Output is correct |
12 |
Correct |
15 ms |
3668 KB |
Output is correct |
13 |
Correct |
29 ms |
5964 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
139 ms |
22372 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
446 ms |
42956 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
620 KB |
Output is correct |
27 |
Correct |
4 ms |
724 KB |
Output is correct |
28 |
Correct |
218 ms |
17392 KB |
Output is correct |
29 |
Correct |
207 ms |
25812 KB |
Output is correct |
30 |
Correct |
421 ms |
34400 KB |
Output is correct |
31 |
Correct |
486 ms |
42884 KB |
Output is correct |
32 |
Correct |
0 ms |
260 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
3 ms |
596 KB |
Output is correct |
45 |
Correct |
180 ms |
21972 KB |
Output is correct |
46 |
Correct |
294 ms |
31672 KB |
Output is correct |
47 |
Correct |
214 ms |
31732 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
423 ms |
42424 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
2 ms |
724 KB |
Output is correct |
58 |
Correct |
7 ms |
1620 KB |
Output is correct |
59 |
Correct |
8 ms |
1600 KB |
Output is correct |
60 |
Correct |
177 ms |
22048 KB |
Output is correct |
61 |
Correct |
291 ms |
29620 KB |
Output is correct |
62 |
Correct |
389 ms |
36712 KB |
Output is correct |
63 |
Correct |
382 ms |
44040 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
1 ms |
312 KB |
Output is correct |
66 |
Correct |
1 ms |
312 KB |
Output is correct |
67 |
Correct |
446 ms |
45008 KB |
Output is correct |
68 |
Correct |
416 ms |
45172 KB |
Output is correct |
69 |
Correct |
383 ms |
44284 KB |
Output is correct |
70 |
Correct |
3 ms |
724 KB |
Output is correct |
71 |
Correct |
6 ms |
1328 KB |
Output is correct |
72 |
Incorrect |
105 ms |
14232 KB |
Solution announced impossible, but it is possible. |
73 |
Halted |
0 ms |
0 KB |
- |