#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e5 + 5;
using pii = pair<int,int>;
#define sz(x) ((int)(x).size())
map<pii, int> encr;
map<int, pii> decr;
vector<int> g[nmax];
int dirx[4] = {-2, 2, 0, 0}, diry[4] = {0, 0, 2, -2};
int occ[nmax];
vector<pii> edges;
void dfs(int node) {
occ[node] = 1;
for(auto x : g[node]) {
if(occ[x]) continue;
edges.emplace_back(node, x);
dfs(x);
}
return;
}
pair<vector<int>, vector<int>> unravel(vector<pii>& v) {
vector<int> a, b;
for(auto [x, y] : v) a.emplace_back(x), b.emplace_back(y);
return make_pair(a, b);
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
for(int i = 0; i < sz(x); i++)
encr[make_pair(x[i], y[i])] = i;
for(auto [a, b] : encr) {
decr[b] = a;
for(int i = 0; i < 4; i++) {
if(encr.count(make_pair(a.first + dirx[i], a.second + diry[i])))
g[b].emplace_back(encr[make_pair(a.first + dirx[i], a.second + diry[i])]);
}
}
dfs(0);
if([&]() {
for(int i = 0; i < sz(x); i++) if(occ[i] == 0) return 1;
return 0;
}()) { return 0; }
map<pii, unordered_set<int>> adj;
vector<pii> avail[5];
for(int i = 0; i < sz(edges); i++) {
auto [x1, y1] = decr[edges[i].first];
auto [x2, y2] = decr[edges[i].second];
if(x1 == x2) {
adj[make_pair(x1 + 1, max(y1, y2) - 1)].emplace(i);
adj[make_pair(x1 - 1, max(y1, y2) - 1)].emplace(i);
}
else {
assert(y1 == y2);
adj[make_pair(max(x1, x2) - 1, y1 - 1)].emplace(i);
adj[make_pair(max(x1, x2) - 1, y1 + 1)].emplace(i);
}
}
for(auto [a, b] : adj) { avail[sz(b)].emplace_back(a); }
vector<pii> assoc(sz(edges));
auto get_top = [&]() {
for(int plane = 1; plane <= 4; plane++) {
while(avail[plane].size()) {
auto a = avail[plane].back();
avail[plane].pop_back();
if(adj.count(a)) return a;
}
}
assert(false);
};
for(int it = 0; it < sz(edges); it++) {
auto T = get_top();
//cerr << T.first << ' ' << T.second << '\t';
int idx = *adj[T].begin();
//cerr << idx << '\n';
{
auto [x1, y1] = decr[edges[idx].first];
auto [x2, y2] = decr[edges[idx].second];
if(x1 == x2) {
auto _1 = make_pair(x1 - 1, max(y1, y2) - 1), _2 = make_pair(x1 + 1, max(y1, y2) - 1);
adj[_1].erase(idx);
adj[_2].erase(idx);
avail[sz(adj[_1])].emplace_back(_1);
avail[sz(adj[_2])].emplace_back(_2);
}
else {
assert(y1 == y2);
auto _1 = make_pair(max(x1, x2) - 1, y1 + 1), _2 = make_pair(max(x1, x2) - 1, y1 - 1);
adj[_1].erase(idx);
adj[_2].erase(idx);
avail[sz(adj[_1])].emplace_back(_1);
avail[sz(adj[_2])].emplace_back(_2);
}
}
adj.erase(T);
assoc[idx] = T;
}
auto [yi, er] = unravel(edges);
auto [san, si] = unravel(assoc);
build(yi, er, san, si);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5104 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
459 ms |
91916 KB |
Output is correct |
10 |
Correct |
31 ms |
13656 KB |
Output is correct |
11 |
Correct |
181 ms |
52180 KB |
Output is correct |
12 |
Correct |
48 ms |
18200 KB |
Output is correct |
13 |
Correct |
41 ms |
16236 KB |
Output is correct |
14 |
Correct |
3 ms |
5212 KB |
Output is correct |
15 |
Correct |
4 ms |
5468 KB |
Output is correct |
16 |
Correct |
419 ms |
87948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5104 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
459 ms |
91916 KB |
Output is correct |
10 |
Correct |
31 ms |
13656 KB |
Output is correct |
11 |
Correct |
181 ms |
52180 KB |
Output is correct |
12 |
Correct |
48 ms |
18200 KB |
Output is correct |
13 |
Correct |
41 ms |
16236 KB |
Output is correct |
14 |
Correct |
3 ms |
5212 KB |
Output is correct |
15 |
Correct |
4 ms |
5468 KB |
Output is correct |
16 |
Correct |
419 ms |
87948 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
2 ms |
5140 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
940 ms |
121628 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
5 ms |
5724 KB |
Output is correct |
26 |
Correct |
5 ms |
5720 KB |
Output is correct |
27 |
Correct |
5 ms |
5724 KB |
Output is correct |
28 |
Correct |
293 ms |
52604 KB |
Output is correct |
29 |
Correct |
458 ms |
73668 KB |
Output is correct |
30 |
Correct |
692 ms |
99012 KB |
Output is correct |
31 |
Correct |
954 ms |
119740 KB |
Output is correct |
32 |
Correct |
2 ms |
4952 KB |
Output is correct |
33 |
Correct |
2 ms |
5208 KB |
Output is correct |
34 |
Correct |
2 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
3 ms |
4952 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 KB |
Output is correct |
40 |
Correct |
2 ms |
5136 KB |
Output is correct |
41 |
Correct |
3 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
4 ms |
5468 KB |
Output is correct |
44 |
Correct |
5 ms |
5720 KB |
Output is correct |
45 |
Runtime error |
280 ms |
138748 KB |
Execution killed with signal 11 |
46 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5104 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
459 ms |
91916 KB |
Output is correct |
10 |
Correct |
31 ms |
13656 KB |
Output is correct |
11 |
Correct |
181 ms |
52180 KB |
Output is correct |
12 |
Correct |
48 ms |
18200 KB |
Output is correct |
13 |
Correct |
41 ms |
16236 KB |
Output is correct |
14 |
Correct |
3 ms |
5212 KB |
Output is correct |
15 |
Correct |
4 ms |
5468 KB |
Output is correct |
16 |
Correct |
419 ms |
87948 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
2 ms |
5140 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
940 ms |
121628 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
5 ms |
5724 KB |
Output is correct |
26 |
Correct |
5 ms |
5720 KB |
Output is correct |
27 |
Correct |
5 ms |
5724 KB |
Output is correct |
28 |
Correct |
293 ms |
52604 KB |
Output is correct |
29 |
Correct |
458 ms |
73668 KB |
Output is correct |
30 |
Correct |
692 ms |
99012 KB |
Output is correct |
31 |
Correct |
954 ms |
119740 KB |
Output is correct |
32 |
Correct |
2 ms |
4952 KB |
Output is correct |
33 |
Correct |
2 ms |
5208 KB |
Output is correct |
34 |
Correct |
2 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
3 ms |
4952 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 KB |
Output is correct |
40 |
Correct |
2 ms |
5136 KB |
Output is correct |
41 |
Correct |
3 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
4 ms |
5468 KB |
Output is correct |
44 |
Correct |
5 ms |
5720 KB |
Output is correct |
45 |
Runtime error |
280 ms |
138748 KB |
Execution killed with signal 11 |
46 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5104 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
459 ms |
91916 KB |
Output is correct |
10 |
Correct |
31 ms |
13656 KB |
Output is correct |
11 |
Correct |
181 ms |
52180 KB |
Output is correct |
12 |
Correct |
48 ms |
18200 KB |
Output is correct |
13 |
Correct |
41 ms |
16236 KB |
Output is correct |
14 |
Correct |
3 ms |
5212 KB |
Output is correct |
15 |
Correct |
4 ms |
5468 KB |
Output is correct |
16 |
Correct |
419 ms |
87948 KB |
Output is correct |
17 |
Correct |
3 ms |
4952 KB |
Output is correct |
18 |
Correct |
2 ms |
4952 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
800 ms |
122768 KB |
Output is correct |
21 |
Runtime error |
825 ms |
237640 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5104 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
459 ms |
91916 KB |
Output is correct |
10 |
Correct |
31 ms |
13656 KB |
Output is correct |
11 |
Correct |
181 ms |
52180 KB |
Output is correct |
12 |
Correct |
48 ms |
18200 KB |
Output is correct |
13 |
Correct |
41 ms |
16236 KB |
Output is correct |
14 |
Correct |
3 ms |
5212 KB |
Output is correct |
15 |
Correct |
4 ms |
5468 KB |
Output is correct |
16 |
Correct |
419 ms |
87948 KB |
Output is correct |
17 |
Runtime error |
883 ms |
341060 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5104 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
459 ms |
91916 KB |
Output is correct |
10 |
Correct |
31 ms |
13656 KB |
Output is correct |
11 |
Correct |
181 ms |
52180 KB |
Output is correct |
12 |
Correct |
48 ms |
18200 KB |
Output is correct |
13 |
Correct |
41 ms |
16236 KB |
Output is correct |
14 |
Correct |
3 ms |
5212 KB |
Output is correct |
15 |
Correct |
4 ms |
5468 KB |
Output is correct |
16 |
Correct |
419 ms |
87948 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
2 ms |
5140 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
940 ms |
121628 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
5 ms |
5724 KB |
Output is correct |
26 |
Correct |
5 ms |
5720 KB |
Output is correct |
27 |
Correct |
5 ms |
5724 KB |
Output is correct |
28 |
Correct |
293 ms |
52604 KB |
Output is correct |
29 |
Correct |
458 ms |
73668 KB |
Output is correct |
30 |
Correct |
692 ms |
99012 KB |
Output is correct |
31 |
Correct |
954 ms |
119740 KB |
Output is correct |
32 |
Correct |
2 ms |
4952 KB |
Output is correct |
33 |
Correct |
2 ms |
5208 KB |
Output is correct |
34 |
Correct |
2 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
3 ms |
4952 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 KB |
Output is correct |
40 |
Correct |
2 ms |
5136 KB |
Output is correct |
41 |
Correct |
3 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
4 ms |
5468 KB |
Output is correct |
44 |
Correct |
5 ms |
5720 KB |
Output is correct |
45 |
Runtime error |
280 ms |
138748 KB |
Execution killed with signal 11 |
46 |
Halted |
0 ms |
0 KB |
- |