# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
999330 |
2024-06-15T10:07:38 Z |
우민규(#10874) |
분수 공원 (IOI21_parks) |
C++17 |
|
495 ms |
125864 KB |
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
if (n == 1) {
build({}, {}, {}, {});
return 1;
}
map<pair<int, int>, int> pts;
map<pair<int, int>, vector<int>> upd;
for (int i = 0; i < n; ++i) pts[{y[i], x[i]}] = i;
int components = n;
vector<int> par(n);
iota(par.begin(), par.end(), 0);
function<int(int)> find = [&](int node) {
return par[node] == node ? node : par[node] = find(par[node]);
};
auto join = [&](int u, int v) {
u = find(u), v = find(v);
if (u != v) {
components -= 1;
par[u] = v;
}
};
vector<int> u, v, a, b;
for (auto [k, i] : pts) {
auto [y, x] = k;
// construct vertical edge
if (pts.count({y - 2, x})) {
int cur = u.size();
u.push_back(pts[{y - 2, x}]);
v.push_back(i);
a.push_back(-69746974);
b.push_back(-69746974);
join(i, pts[{y - 2, x}]);
upd[{y - 1, x - 1}].push_back(cur);
upd[{y - 1, x + 1}].push_back(cur);
}
if (pts.count({y, x - 2})) {
int cur = v.size();
u.push_back(pts[{y, x - 2}]);
v.push_back(i);
a.push_back(-69746974);
b.push_back(-69746974);
join(i, pts[{y, x - 2}]);
upd[{y - 1, x - 1}].push_back(cur);
upd[{y + 1, x - 1}].push_back(cur);
}
}
if (components > 1) {
return 0;
}
function<void(int)> upd_trav;
// select at point p
function<void(int, int, int, int, int)> sel_upd = [&](int x, int y, int xp,
int yp, int v) {
vector<int> tmp;
upd[{y, x}].swap(tmp);
a[v] = x;
b[v] = y;
// if (v == 0) {
// int t = 3;
// }
// cout << "SET " << v << ": " << x << " " << y << ", " << xp << " " << yp
// << "\n";
// for (auto t : upd[{yp, xp}]) {
// cout << t << ", ";
// }
// cout << "\n";
auto it = std::find(upd[{yp, xp}].begin(), upd[{yp, xp}].end(), v);
if (it != upd[{yp, xp}].end()) upd[{yp, xp}].erase(it);
// for (auto t : upd[{yp, xp}]) {
// cout << t << ", ";
// }
// cout << "\n";
for (auto p : tmp)
if (p != v) upd_trav(p);
if (!upd[{yp, xp}].empty()) {
tmp.clear();
upd[{yp, xp}].swap(tmp);
for (auto p : tmp) upd_trav(p);
}
};
upd_trav = [&](int p) {
int cx = (x[u[p]] + x[v[p]]) / 2;
int cy = (y[u[p]] + y[v[p]]) / 2;
if (x[u[p]] != x[v[p]]) {
// {x, y+1}, {x, y-1}
if (std::find(upd[{cy + 1, cx}].begin(), upd[{cy + 1, cx}].end(), p) !=
upd[{cy + 1, cx}].end()) {
sel_upd(cx, cy + 1, cx, cy - 1, p);
} else {
sel_upd(cx, cy - 1, cx, cy + 1, p);
}
} else {
if (std::find(upd[{cy, cx - 1}].begin(), upd[{cy, cx - 1}].end(), p) !=
upd[{cy, cx - 1}].end()) {
sel_upd(cx - 1, cy, cx + 1, cy, p);
} else {
sel_upd(cx + 1, cy, cx - 1, cy, p);
}
}
};
for (int i = 0; i < u.size(); ++i) {
if (a[i] == -69746974 && b[i] == -69746974) {
upd_trav(i);
}
}
build(u, v, a, b);
return 1;
}
#ifndef EVAL
#include "grader.cpp"
#endif
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:107:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for (int i = 0; i < u.size(); ++i) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
504 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
219 ms |
35208 KB |
Output is correct |
10 |
Correct |
19 ms |
3928 KB |
Output is correct |
11 |
Correct |
98 ms |
19108 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
43 ms |
14340 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
219 ms |
35128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
504 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
219 ms |
35208 KB |
Output is correct |
10 |
Correct |
19 ms |
3928 KB |
Output is correct |
11 |
Correct |
98 ms |
19108 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
43 ms |
14340 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
219 ms |
35128 KB |
Output is correct |
17 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
495 ms |
101176 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
1000 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
4 ms |
1348 KB |
Output is correct |
28 |
Correct |
183 ms |
40808 KB |
Output is correct |
29 |
Correct |
273 ms |
60828 KB |
Output is correct |
30 |
Correct |
373 ms |
82600 KB |
Output is correct |
31 |
Correct |
488 ms |
103032 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
436 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
856 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
191 ms |
29112 KB |
Output is correct |
46 |
Correct |
311 ms |
42232 KB |
Output is correct |
47 |
Correct |
278 ms |
42152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
504 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
219 ms |
35208 KB |
Output is correct |
10 |
Correct |
19 ms |
3928 KB |
Output is correct |
11 |
Correct |
98 ms |
19108 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
43 ms |
14340 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
219 ms |
35128 KB |
Output is correct |
17 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
495 ms |
101176 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
1000 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
4 ms |
1348 KB |
Output is correct |
28 |
Correct |
183 ms |
40808 KB |
Output is correct |
29 |
Correct |
273 ms |
60828 KB |
Output is correct |
30 |
Correct |
373 ms |
82600 KB |
Output is correct |
31 |
Correct |
488 ms |
103032 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
436 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
856 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
191 ms |
29112 KB |
Output is correct |
46 |
Correct |
311 ms |
42232 KB |
Output is correct |
47 |
Correct |
278 ms |
42152 KB |
Output is correct |
48 |
Correct |
0 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 |
Incorrect |
0 ms |
436 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 3 |
52 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
504 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
219 ms |
35208 KB |
Output is correct |
10 |
Correct |
19 ms |
3928 KB |
Output is correct |
11 |
Correct |
98 ms |
19108 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
43 ms |
14340 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
219 ms |
35128 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 |
457 ms |
123304 KB |
Output is correct |
21 |
Correct |
470 ms |
85704 KB |
Output is correct |
22 |
Correct |
481 ms |
87968 KB |
Output is correct |
23 |
Correct |
382 ms |
61348 KB |
Output is correct |
24 |
Correct |
138 ms |
18512 KB |
Output is correct |
25 |
Correct |
243 ms |
65180 KB |
Output is correct |
26 |
Correct |
274 ms |
65192 KB |
Output is correct |
27 |
Correct |
468 ms |
71468 KB |
Output is correct |
28 |
Correct |
464 ms |
71588 KB |
Output is correct |
29 |
Correct |
396 ms |
71588 KB |
Output is correct |
30 |
Correct |
408 ms |
71592 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
26 ms |
4700 KB |
Output is correct |
33 |
Correct |
56 ms |
9812 KB |
Output is correct |
34 |
Correct |
440 ms |
125864 KB |
Output is correct |
35 |
Correct |
9 ms |
2648 KB |
Output is correct |
36 |
Correct |
52 ms |
12392 KB |
Output is correct |
37 |
Correct |
114 ms |
24312 KB |
Output is correct |
38 |
Correct |
175 ms |
22196 KB |
Output is correct |
39 |
Correct |
213 ms |
30372 KB |
Output is correct |
40 |
Correct |
303 ms |
38288 KB |
Output is correct |
41 |
Correct |
376 ms |
46520 KB |
Output is correct |
42 |
Correct |
411 ms |
54692 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 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 |
344 KB |
Output is correct |
54 |
Correct |
2 ms |
860 KB |
Output is correct |
55 |
Correct |
3 ms |
1116 KB |
Output is correct |
56 |
Correct |
202 ms |
29168 KB |
Output is correct |
57 |
Correct |
278 ms |
42076 KB |
Output is correct |
58 |
Correct |
270 ms |
42148 KB |
Output is correct |
59 |
Correct |
0 ms |
344 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
604 KB |
Output is correct |
62 |
Correct |
450 ms |
71580 KB |
Output is correct |
63 |
Correct |
492 ms |
71604 KB |
Output is correct |
64 |
Correct |
452 ms |
71352 KB |
Output is correct |
65 |
Correct |
4 ms |
1268 KB |
Output is correct |
66 |
Correct |
8 ms |
2396 KB |
Output is correct |
67 |
Correct |
185 ms |
28480 KB |
Output is correct |
68 |
Correct |
311 ms |
42916 KB |
Output is correct |
69 |
Correct |
409 ms |
56924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
504 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
219 ms |
35208 KB |
Output is correct |
10 |
Correct |
19 ms |
3928 KB |
Output is correct |
11 |
Correct |
98 ms |
19108 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
43 ms |
14340 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
219 ms |
35128 KB |
Output is correct |
17 |
Correct |
460 ms |
70020 KB |
Output is correct |
18 |
Correct |
483 ms |
72180 KB |
Output is correct |
19 |
Correct |
456 ms |
125592 KB |
Output is correct |
20 |
Correct |
448 ms |
59048 KB |
Output is correct |
21 |
Correct |
368 ms |
59560 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
58 ms |
9360 KB |
Output is correct |
24 |
Correct |
20 ms |
5464 KB |
Output is correct |
25 |
Correct |
82 ms |
18384 KB |
Output is correct |
26 |
Correct |
143 ms |
31144 KB |
Output is correct |
27 |
Correct |
222 ms |
29844 KB |
Output is correct |
28 |
Correct |
283 ms |
37288 KB |
Output is correct |
29 |
Correct |
371 ms |
44712 KB |
Output is correct |
30 |
Correct |
421 ms |
51836 KB |
Output is correct |
31 |
Correct |
489 ms |
59304 KB |
Output is correct |
32 |
Correct |
494 ms |
64764 KB |
Output is correct |
33 |
Correct |
478 ms |
71588 KB |
Output is correct |
34 |
Correct |
5 ms |
1628 KB |
Output is correct |
35 |
Correct |
12 ms |
2864 KB |
Output is correct |
36 |
Correct |
188 ms |
30208 KB |
Output is correct |
37 |
Correct |
289 ms |
45384 KB |
Output is correct |
38 |
Correct |
415 ms |
60068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
504 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
219 ms |
35208 KB |
Output is correct |
10 |
Correct |
19 ms |
3928 KB |
Output is correct |
11 |
Correct |
98 ms |
19108 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
43 ms |
14340 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
219 ms |
35128 KB |
Output is correct |
17 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
495 ms |
101176 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
1000 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
4 ms |
1348 KB |
Output is correct |
28 |
Correct |
183 ms |
40808 KB |
Output is correct |
29 |
Correct |
273 ms |
60828 KB |
Output is correct |
30 |
Correct |
373 ms |
82600 KB |
Output is correct |
31 |
Correct |
488 ms |
103032 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
436 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
856 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
191 ms |
29112 KB |
Output is correct |
46 |
Correct |
311 ms |
42232 KB |
Output is correct |
47 |
Correct |
278 ms |
42152 KB |
Output is correct |
48 |
Correct |
0 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 |
Incorrect |
0 ms |
436 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 3 |
52 |
Halted |
0 ms |
0 KB |
- |