#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
const int mxN = 2e5 + 1;
const int dx[mxN] = {0, 1, 0, -1}, dy[mxN] = {1, 0, -1, 0};
bool vis[mxN];
pair<pii, int> pts[mxN];
pii opts[mxN];
map<pii, int> allpts;
int n;
bool CheckConnected() {
queue<pii> q;
set<pii> track;
q.push(pts[0].ff);
track.insert(pts[0].ff);
while (!q.empty()) {
pii cur = q.front();
q.pop();
for (int k = 0; k < 4; k++) {
int nx = cur.ff + dx[k] * 2;
int ny = cur.ss + dy[k] * 2;
if (allpts.find({nx, ny}) != allpts.end() && track.find({nx, ny}) == track.end()) {
q.push({nx, ny});
track.insert({nx, ny});
}
}
}
return (int(track.size()) == n);
}
bool sortx(pair<pii, int> a, pair<pii, int> b) {
if (a.ff.ss != b.ff.ss) return a.ff.ss < b.ff.ss;
return a.ff.ff < b.ff.ff;
}
bool sorty(pair<pii, int> a, pair<pii, int> b) {
if (a.ff.ff != b.ff.ff) return a.ff.ff < b.ff.ff;
return a.ff.ss < b.ff.ss;
}
void st3() {
int arr[3][mxN + 10];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < mxN + 10; j++) {
arr[i][j] = -1;
}
}
for (int i = 0; i < n; i++) {
arr[(pts[i].ff.ff >> 1) - 1][pts[i].ff.ss] = pts[i].ss;
}
bool con01 = false, con12 = false;
bool notfix = false;
vector<int> u, v, a, b;
for (int i = 0; i < mxN + 6; i += 2) {
// if (i <= 10) cout << arr[0][i] << ' ' << arr[1][i] << ' ' << arr[2][i] << endl;
if (arr[0][i] >= 0 && arr[0][i + 2] >= 0) {
u.pb(arr[0][i]); v.pb(arr[0][i + 2]);
a.pb(1); b.pb(i + 1);
}
if (arr[2][i] >= 0 && arr[2][i + 2] >= 0) {
u.pb(arr[2][i]); v.pb(arr[2][i + 2]);
a.pb(7); b.pb(i + 1);
}
bool special = false;
if (notfix) {
u.pb(arr[0][i]); v.pb(arr[1][i]);
a.pb(3); b.pb(i + 1);
special = true;
notfix = false;
}
bool usemid = false;
if (arr[1][i] >= 0 && arr[1][i + 2] >= 0) {
u.pb(arr[1][i]); v.pb(arr[1][i + 2]);
a.pb((special ? 5 : 3)); b.pb(i + 1);
usemid = true;
}
if (arr[0][i + 2] >= 0 && arr[1][i + 2] >= 0 && !con01) {
if (!usemid) {
u.pb(arr[0][i + 2]); v.pb(arr[1][i + 2]);
a.pb(3); b.pb(i + 1);
} else notfix = true;
con01 = true;
} else con01 = false;
if (arr[1][i + 2] >= 0 && arr[2][i + 2] >= 0 && !con12) {
u.pb(arr[1][i + 2]); v.pb(arr[2][i + 2]);
a.pb(5); b.pb(i + 1);
con12 = true;
} else con12 = false;
}
build(u, v, a, b);
return;
}
int construct_roads(vector<int> ox, vector<int> oy) {
n = ox.size();
int maxx = 0;
for (int i = 0; i < n; i++) {
pts[i] = {{ox[i], oy[i]}, i};
opts[i] = pts[i].ff;
allpts[pts[i].ff] = i;
maxx = max(maxx, pts[i].ff.ff);
}
// for (int i = 0; i < n; i++) {
// cout << pts[i].ff.ff << ' ' << pts[i].ff.ss << ' ' << pts[i].ss << endl;
// }
if (!CheckConnected()) return 0;
if (maxx <= 6) st3();
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 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 |
150 ms |
19988 KB |
Output is correct |
10 |
Correct |
14 ms |
4436 KB |
Output is correct |
11 |
Correct |
80 ms |
11900 KB |
Output is correct |
12 |
Correct |
21 ms |
5328 KB |
Output is correct |
13 |
Correct |
37 ms |
6308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
159 ms |
20328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 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 |
150 ms |
19988 KB |
Output is correct |
10 |
Correct |
14 ms |
4436 KB |
Output is correct |
11 |
Correct |
80 ms |
11900 KB |
Output is correct |
12 |
Correct |
21 ms |
5328 KB |
Output is correct |
13 |
Correct |
37 ms |
6308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
159 ms |
20328 KB |
Output is correct |
17 |
Correct |
2 ms |
2656 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
3 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
312 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
408 ms |
39936 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
3 ms |
2900 KB |
Output is correct |
26 |
Correct |
3 ms |
584 KB |
Output is correct |
27 |
Correct |
3 ms |
716 KB |
Output is correct |
28 |
Correct |
139 ms |
17692 KB |
Output is correct |
29 |
Correct |
263 ms |
25588 KB |
Output is correct |
30 |
Correct |
374 ms |
33248 KB |
Output is correct |
31 |
Correct |
478 ms |
40868 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
3 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
2 ms |
2616 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
2 ms |
2644 KB |
Output is correct |
40 |
Correct |
2 ms |
2644 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
2 ms |
2620 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
2 ms |
596 KB |
Output is correct |
45 |
Correct |
168 ms |
19976 KB |
Output is correct |
46 |
Correct |
244 ms |
28992 KB |
Output is correct |
47 |
Correct |
284 ms |
28972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 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 |
150 ms |
19988 KB |
Output is correct |
10 |
Correct |
14 ms |
4436 KB |
Output is correct |
11 |
Correct |
80 ms |
11900 KB |
Output is correct |
12 |
Correct |
21 ms |
5328 KB |
Output is correct |
13 |
Correct |
37 ms |
6308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
159 ms |
20328 KB |
Output is correct |
17 |
Correct |
2 ms |
2656 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
3 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
312 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
408 ms |
39936 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
3 ms |
2900 KB |
Output is correct |
26 |
Correct |
3 ms |
584 KB |
Output is correct |
27 |
Correct |
3 ms |
716 KB |
Output is correct |
28 |
Correct |
139 ms |
17692 KB |
Output is correct |
29 |
Correct |
263 ms |
25588 KB |
Output is correct |
30 |
Correct |
374 ms |
33248 KB |
Output is correct |
31 |
Correct |
478 ms |
40868 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
3 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
2 ms |
2616 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
2 ms |
2644 KB |
Output is correct |
40 |
Correct |
2 ms |
2644 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
2 ms |
2620 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
2 ms |
596 KB |
Output is correct |
45 |
Correct |
168 ms |
19976 KB |
Output is correct |
46 |
Correct |
244 ms |
28992 KB |
Output is correct |
47 |
Correct |
284 ms |
28972 KB |
Output is correct |
48 |
Correct |
2 ms |
2644 KB |
Output is correct |
49 |
Correct |
1 ms |
2644 KB |
Output is correct |
50 |
Correct |
1 ms |
2644 KB |
Output is correct |
51 |
Correct |
1 ms |
2644 KB |
Output is correct |
52 |
Correct |
2 ms |
2644 KB |
Output is correct |
53 |
Correct |
2 ms |
2644 KB |
Output is correct |
54 |
Correct |
2 ms |
2644 KB |
Output is correct |
55 |
Correct |
512 ms |
41472 KB |
Output is correct |
56 |
Correct |
3 ms |
2644 KB |
Output is correct |
57 |
Incorrect |
5 ms |
3028 KB |
Tree @(5, 185601) appears more than once: for edges on positions 6 and 7 |
58 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 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 |
150 ms |
19988 KB |
Output is correct |
10 |
Correct |
14 ms |
4436 KB |
Output is correct |
11 |
Correct |
80 ms |
11900 KB |
Output is correct |
12 |
Correct |
21 ms |
5328 KB |
Output is correct |
13 |
Correct |
37 ms |
6308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
159 ms |
20328 KB |
Output is correct |
17 |
Incorrect |
1 ms |
312 KB |
Wrong answer detected in grader |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 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 |
150 ms |
19988 KB |
Output is correct |
10 |
Correct |
14 ms |
4436 KB |
Output is correct |
11 |
Correct |
80 ms |
11900 KB |
Output is correct |
12 |
Correct |
21 ms |
5328 KB |
Output is correct |
13 |
Correct |
37 ms |
6308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
159 ms |
20328 KB |
Output is correct |
17 |
Incorrect |
368 ms |
31032 KB |
Wrong answer detected in grader |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 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 |
150 ms |
19988 KB |
Output is correct |
10 |
Correct |
14 ms |
4436 KB |
Output is correct |
11 |
Correct |
80 ms |
11900 KB |
Output is correct |
12 |
Correct |
21 ms |
5328 KB |
Output is correct |
13 |
Correct |
37 ms |
6308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
159 ms |
20328 KB |
Output is correct |
17 |
Correct |
2 ms |
2656 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
3 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
312 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
408 ms |
39936 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
3 ms |
2900 KB |
Output is correct |
26 |
Correct |
3 ms |
584 KB |
Output is correct |
27 |
Correct |
3 ms |
716 KB |
Output is correct |
28 |
Correct |
139 ms |
17692 KB |
Output is correct |
29 |
Correct |
263 ms |
25588 KB |
Output is correct |
30 |
Correct |
374 ms |
33248 KB |
Output is correct |
31 |
Correct |
478 ms |
40868 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
3 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
2 ms |
2616 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
2 ms |
2644 KB |
Output is correct |
40 |
Correct |
2 ms |
2644 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
2 ms |
2620 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
2 ms |
596 KB |
Output is correct |
45 |
Correct |
168 ms |
19976 KB |
Output is correct |
46 |
Correct |
244 ms |
28992 KB |
Output is correct |
47 |
Correct |
284 ms |
28972 KB |
Output is correct |
48 |
Correct |
2 ms |
2644 KB |
Output is correct |
49 |
Correct |
1 ms |
2644 KB |
Output is correct |
50 |
Correct |
1 ms |
2644 KB |
Output is correct |
51 |
Correct |
1 ms |
2644 KB |
Output is correct |
52 |
Correct |
2 ms |
2644 KB |
Output is correct |
53 |
Correct |
2 ms |
2644 KB |
Output is correct |
54 |
Correct |
2 ms |
2644 KB |
Output is correct |
55 |
Correct |
512 ms |
41472 KB |
Output is correct |
56 |
Correct |
3 ms |
2644 KB |
Output is correct |
57 |
Incorrect |
5 ms |
3028 KB |
Tree @(5, 185601) appears more than once: for edges on positions 6 and 7 |
58 |
Halted |
0 ms |
0 KB |
- |