# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
999320 |
2024-06-15T09:53:22 Z |
우민규(#10874) |
분수 공원 (IOI21_parks) |
C++17 |
|
480 ms |
123320 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;
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 p : tmp)
if (p != v) upd_trav(p);
if (!upd[{yp, xp}].empty()) {
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:93:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | 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 |
348 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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
196 ms |
35216 KB |
Output is correct |
10 |
Correct |
15 ms |
3932 KB |
Output is correct |
11 |
Correct |
89 ms |
19144 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
40 ms |
14276 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
205 ms |
35272 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 |
348 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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
196 ms |
35216 KB |
Output is correct |
10 |
Correct |
15 ms |
3932 KB |
Output is correct |
11 |
Correct |
89 ms |
19144 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
40 ms |
14276 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
205 ms |
35272 KB |
Output is correct |
17 |
Correct |
0 ms |
348 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 |
461 ms |
101372 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
856 KB |
Output is correct |
26 |
Correct |
3 ms |
1232 KB |
Output is correct |
27 |
Correct |
4 ms |
1372 KB |
Output is correct |
28 |
Correct |
177 ms |
40744 KB |
Output is correct |
29 |
Incorrect |
263 ms |
60836 KB |
Tree @(3, 80003) appears more than once: for edges on positions 1 and 2 |
30 |
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 |
348 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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
196 ms |
35216 KB |
Output is correct |
10 |
Correct |
15 ms |
3932 KB |
Output is correct |
11 |
Correct |
89 ms |
19144 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
40 ms |
14276 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
205 ms |
35272 KB |
Output is correct |
17 |
Correct |
0 ms |
348 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 |
461 ms |
101372 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
856 KB |
Output is correct |
26 |
Correct |
3 ms |
1232 KB |
Output is correct |
27 |
Correct |
4 ms |
1372 KB |
Output is correct |
28 |
Correct |
177 ms |
40744 KB |
Output is correct |
29 |
Incorrect |
263 ms |
60836 KB |
Tree @(3, 80003) appears more than once: for edges on positions 1 and 2 |
30 |
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 |
348 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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
196 ms |
35216 KB |
Output is correct |
10 |
Correct |
15 ms |
3932 KB |
Output is correct |
11 |
Correct |
89 ms |
19144 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
40 ms |
14276 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
205 ms |
35272 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
436 ms |
123320 KB |
Output is correct |
21 |
Incorrect |
434 ms |
85600 KB |
Tree @(5, 9) appears more than once: for edges on positions 9 and 10 |
22 |
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 |
348 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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
196 ms |
35216 KB |
Output is correct |
10 |
Correct |
15 ms |
3932 KB |
Output is correct |
11 |
Correct |
89 ms |
19144 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
40 ms |
14276 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
205 ms |
35272 KB |
Output is correct |
17 |
Incorrect |
480 ms |
70000 KB |
Tree @(3, 100001) appears more than once: for edges on positions 149998 and 149999 |
18 |
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 |
348 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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
196 ms |
35216 KB |
Output is correct |
10 |
Correct |
15 ms |
3932 KB |
Output is correct |
11 |
Correct |
89 ms |
19144 KB |
Output is correct |
12 |
Correct |
22 ms |
5724 KB |
Output is correct |
13 |
Correct |
40 ms |
14276 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
205 ms |
35272 KB |
Output is correct |
17 |
Correct |
0 ms |
348 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 |
461 ms |
101372 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
856 KB |
Output is correct |
26 |
Correct |
3 ms |
1232 KB |
Output is correct |
27 |
Correct |
4 ms |
1372 KB |
Output is correct |
28 |
Correct |
177 ms |
40744 KB |
Output is correct |
29 |
Incorrect |
263 ms |
60836 KB |
Tree @(3, 80003) appears more than once: for edges on positions 1 and 2 |
30 |
Halted |
0 ms |
0 KB |
- |