#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "parks.h"
int n;
VVI gp;
VPI cord;
VPI bench(int u, int v) {
int dir = -1;
if (gp[u][0] == v) dir = 0;
else if (gp[u][1] == v) dir = 1;
else if (gp[u][2] == v) dir = 2;
else if (gp[u][3] == v) dir = 3;
assert(dir != -1);
int x, y;
tie(x, y) = cord[u];
if (dir == 0) return {{x-1, y-1}, {x-1, y+1}};
if (dir == 1) return {{x-1, y+1}, {x+1, y+1}};
if (dir == 2) return {{x+1, y+1}, {x+1, y-1}};
if (dir == 3) return {{x+1, y-1}, {x-1, y-1}};
return {};
}
VPI edges;
VI vis;
void dfs(int u) {
vis[u] = 1;
for (int v : gp[u]) if (v != -1) {
if (vis[v] == 1) {
/* (u, v) is a back-edge */
} else if (vis[v] == 0) {
/* (u, v) is a span-edge */
edges.pb({u, v});
dfs(v);
}
}
vis[u] = 2;
}
void build(VPI edges, VPI benches) {
int m = edges.size();
VI ret[4];
rep(i, m) ret[0].pb(edges[i].ff);
rep(i, m) ret[1].pb(edges[i].ss);
rep(i, m) ret[2].pb(benches[i].ff);
rep(i, m) ret[3].pb(benches[i].ss);
build(ret[0], ret[1], ret[2], ret[3]);
}
bool order(int type) {
VPI benches;
set<PII> st;
for (auto[u, v] : edges) {
bool good = false;
VPI ret = bench(u, v);
if (type == 2) swap(ret[0], ret[1]);
else if (type == 3) {
if (rand()%2) swap(ret[0], ret[1]);
}
for (auto[x, y] : ret) {
if (st.count({x, y})) continue;
good = true;
benches.pb({x, y});
st.insert({x, y});
break;
}
if (!good) return false;
}
build(edges, benches);
return true;
}
int construct_roads(VI x_arg, VI y_arg) {
srand(time(0));
if (true) {
n = x_arg.size();
cord = VPI(n);
rep(i, n) cord[i] = {x_arg[i], y_arg[i]};
gp = VVI(n);
map<PII, int> mp;
rep(i, n) mp[{x_arg[i], y_arg[i]}] = i;
rep(u, n) {
int x = x_arg[u];
int y = y_arg[u];
if (mp.count({x-2, y})) {
gp[u].pb(mp[{x-2, y}]);
} else gp[u].pb(-1);
if (mp.count({x, y+2})) {
gp[u].pb(mp[{x, y+2}]);
} else gp[u].pb(-1);
if (mp.count({x+2, y})) {
gp[u].pb(mp[{x+2, y}]);
} else gp[u].pb(-1);
if (mp.count({x, y-2})) {
gp[u].pb(mp[{x, y-2}]);
} else gp[u].pb(-1);
}
}
vis = VI(n);
dfs(0);
for (int x : vis) if (x == 0) return 0;
rep(type, 3) {
if (order(type)) return 1;
}
assert(false);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
160 ms |
29388 KB |
Output is correct |
10 |
Correct |
11 ms |
3456 KB |
Output is correct |
11 |
Correct |
70 ms |
16432 KB |
Output is correct |
12 |
Correct |
15 ms |
4952 KB |
Output is correct |
13 |
Correct |
34 ms |
9308 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
152 ms |
26464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
160 ms |
29388 KB |
Output is correct |
10 |
Correct |
11 ms |
3456 KB |
Output is correct |
11 |
Correct |
70 ms |
16432 KB |
Output is correct |
12 |
Correct |
15 ms |
4952 KB |
Output is correct |
13 |
Correct |
34 ms |
9308 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
152 ms |
26464 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
449 ms |
58584 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
4 ms |
860 KB |
Output is correct |
28 |
Correct |
152 ms |
24356 KB |
Output is correct |
29 |
Correct |
238 ms |
35928 KB |
Output is correct |
30 |
Correct |
340 ms |
48396 KB |
Output is correct |
31 |
Correct |
478 ms |
57056 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
856 KB |
Output is correct |
45 |
Correct |
178 ms |
27408 KB |
Output is correct |
46 |
Correct |
296 ms |
40488 KB |
Output is correct |
47 |
Correct |
296 ms |
39500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
160 ms |
29388 KB |
Output is correct |
10 |
Correct |
11 ms |
3456 KB |
Output is correct |
11 |
Correct |
70 ms |
16432 KB |
Output is correct |
12 |
Correct |
15 ms |
4952 KB |
Output is correct |
13 |
Correct |
34 ms |
9308 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
152 ms |
26464 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
449 ms |
58584 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
4 ms |
860 KB |
Output is correct |
28 |
Correct |
152 ms |
24356 KB |
Output is correct |
29 |
Correct |
238 ms |
35928 KB |
Output is correct |
30 |
Correct |
340 ms |
48396 KB |
Output is correct |
31 |
Correct |
478 ms |
57056 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
856 KB |
Output is correct |
45 |
Correct |
178 ms |
27408 KB |
Output is correct |
46 |
Correct |
296 ms |
40488 KB |
Output is correct |
47 |
Correct |
296 ms |
39500 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
480 ms |
55688 KB |
Output is correct |
56 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
57 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
160 ms |
29388 KB |
Output is correct |
10 |
Correct |
11 ms |
3456 KB |
Output is correct |
11 |
Correct |
70 ms |
16432 KB |
Output is correct |
12 |
Correct |
15 ms |
4952 KB |
Output is correct |
13 |
Correct |
34 ms |
9308 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
152 ms |
26464 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
413 ms |
60844 KB |
Output is correct |
21 |
Correct |
453 ms |
57520 KB |
Output is correct |
22 |
Correct |
422 ms |
55880 KB |
Output is correct |
23 |
Correct |
310 ms |
46688 KB |
Output is correct |
24 |
Correct |
268 ms |
30292 KB |
Output is correct |
25 |
Correct |
352 ms |
30152 KB |
Output is correct |
26 |
Correct |
308 ms |
30036 KB |
Output is correct |
27 |
Correct |
404 ms |
44652 KB |
Output is correct |
28 |
Runtime error |
378 ms |
59472 KB |
Execution killed with signal 6 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
160 ms |
29388 KB |
Output is correct |
10 |
Correct |
11 ms |
3456 KB |
Output is correct |
11 |
Correct |
70 ms |
16432 KB |
Output is correct |
12 |
Correct |
15 ms |
4952 KB |
Output is correct |
13 |
Correct |
34 ms |
9308 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
152 ms |
26464 KB |
Output is correct |
17 |
Correct |
419 ms |
60580 KB |
Output is correct |
18 |
Correct |
377 ms |
59208 KB |
Output is correct |
19 |
Correct |
519 ms |
60972 KB |
Output is correct |
20 |
Runtime error |
418 ms |
78676 KB |
Execution killed with signal 6 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
160 ms |
29388 KB |
Output is correct |
10 |
Correct |
11 ms |
3456 KB |
Output is correct |
11 |
Correct |
70 ms |
16432 KB |
Output is correct |
12 |
Correct |
15 ms |
4952 KB |
Output is correct |
13 |
Correct |
34 ms |
9308 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
152 ms |
26464 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
449 ms |
58584 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
4 ms |
860 KB |
Output is correct |
28 |
Correct |
152 ms |
24356 KB |
Output is correct |
29 |
Correct |
238 ms |
35928 KB |
Output is correct |
30 |
Correct |
340 ms |
48396 KB |
Output is correct |
31 |
Correct |
478 ms |
57056 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
856 KB |
Output is correct |
45 |
Correct |
178 ms |
27408 KB |
Output is correct |
46 |
Correct |
296 ms |
40488 KB |
Output is correct |
47 |
Correct |
296 ms |
39500 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
480 ms |
55688 KB |
Output is correct |
56 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
57 |
Halted |
0 ms |
0 KB |
- |