# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
421800 |
2021-06-09T12:18:07 Z |
palilo |
None (KOI16_laser) |
C++17 |
|
195 ms |
18284 KB |
#include <bits/stdc++.h>
using namespace std;
namespace std {
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template <class Fun>
class y_combinator_result {
Fun fun_;
public:
template <class T>
explicit y_combinator_result(T&& fun) : fun_(std::forward<T>(fun)) {}
template <class... Args>
decltype(auto) operator()(Args&&... args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template <class Fun>
decltype(auto) y_combinator(Fun&& fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
}; // namespace std
struct point {
int x, y, id;
point() = default;
point(int _x, int _y, int _id) : x(_x), y(_y), id(_id) {}
using P = point;
bool operator<(const P& p) const { return tie(x, y) < tie(p.x, p.y); }
bool operator==(const P& p) const { return id == p.id; }
int64_t cross(const P& a, const P& b) const { return int64_t(a.x - x) * (b.y - y) - int64_t(a.y - y) * (b.x - x); }
};
vector<point> convex_hull(vector<point> pts) {
sort(pts.begin(), pts.end());
vector<point> hull(pts.size() + 1);
int s = 0, t = 0;
for (int it = 2; it--; s = --t, reverse(pts.begin(), pts.end()))
for (const auto& p : pts) {
while (t >= s + 2 && hull[t - 2].cross(hull[t - 1], p) <= 0) t--;
hull[t++] = p;
}
return {hull.begin(), hull.begin() + t - (t == 2 && hull[0] == hull[1])};
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifdef palilo
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
int n;
cin >> n;
vector<point> a(3 * n);
for (int i = 0; i < n; ++i)
cin >> a[i].x >> a[i].y, a[i].id = ~i;
for (int i = n; i < 3 * n; ++i)
cin >> a[i].x >> a[i].y, a[i].id = i - n;
vector<pair<int, int>> ans(n);
y_combinator([&](auto self, auto st, auto ed) -> void {
if (st == ed) return;
if (ed - st == 3) {
swap(*st, *find_if(st, ed, [&](const auto& x) { return x.id < 0; }));
ans[~st->id] = {(st + 1)->id, (st + 2)->id};
return;
}
auto hull = convex_hull({st, ed});
point pivot;
bool is_blue; // pivot is blue?
if (auto it = find_if(hull.begin(), hull.end(), [&](const auto& x) { return x.id < 0; }); it == hull.end())
pivot = hull.front(), is_blue = false;
else
pivot = *it, is_blue = true;
swap(*st, *find(st, ed, pivot));
sort(st + 1, ed, [&](const auto& lhs, const auto& rhs) {
return st->cross(lhs, rhs) > 0;
});
int sum = 0;
if (is_blue) {
vector<point>::iterator r;
for (auto it = st; it != ed; ++it) {
if (it->id < 0) sum += 2;
else {
--sum;
if (sum == 1) r = prev(it);
if (sum == 0) {
swap(*st, *r);
self(st, r), self(r, it + 1), self(it + 1, ed);
return;
}
}
}
} else {
for (auto it = st; it != ed - 1; ++it) {
sum += it->id < 0 ? 2 : -1;
if (sum == 0) {
self(st, it + 1), self(it + 1, ed);
return;
}
}
sum = -1;
for (auto it = ed - 1; it != st; --it) {
sum += it->id < 0 ? 2 : -1;
if (sum == 0) {
swap(*st, *prev(it));
self(st, it - 1), self(it - 1, ed);
return;
}
}
}
assert(false);
})(a.begin(), a.end());
for (const auto& [i, j] : ans)
cout << i + 1 << ' ' << j + 1 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
304 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
308 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
304 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
308 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
460 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
2 ms |
320 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
2 ms |
460 KB |
Output is correct |
50 |
Correct |
2 ms |
460 KB |
Output is correct |
51 |
Correct |
2 ms |
460 KB |
Output is correct |
52 |
Correct |
2 ms |
460 KB |
Output is correct |
53 |
Correct |
2 ms |
440 KB |
Output is correct |
54 |
Correct |
2 ms |
460 KB |
Output is correct |
55 |
Correct |
2 ms |
444 KB |
Output is correct |
56 |
Correct |
2 ms |
460 KB |
Output is correct |
57 |
Correct |
2 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
2 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
1 ms |
332 KB |
Output is correct |
62 |
Correct |
1 ms |
332 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
1 ms |
332 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
1 ms |
332 KB |
Output is correct |
67 |
Correct |
1 ms |
332 KB |
Output is correct |
68 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
304 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
308 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
460 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
2 ms |
320 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
2 ms |
460 KB |
Output is correct |
50 |
Correct |
2 ms |
460 KB |
Output is correct |
51 |
Correct |
2 ms |
460 KB |
Output is correct |
52 |
Correct |
2 ms |
460 KB |
Output is correct |
53 |
Correct |
2 ms |
440 KB |
Output is correct |
54 |
Correct |
2 ms |
460 KB |
Output is correct |
55 |
Correct |
2 ms |
444 KB |
Output is correct |
56 |
Correct |
2 ms |
460 KB |
Output is correct |
57 |
Correct |
2 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
2 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
1 ms |
332 KB |
Output is correct |
62 |
Correct |
1 ms |
332 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
1 ms |
332 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
1 ms |
332 KB |
Output is correct |
67 |
Correct |
1 ms |
332 KB |
Output is correct |
68 |
Correct |
1 ms |
332 KB |
Output is correct |
69 |
Correct |
20 ms |
520 KB |
Output is correct |
70 |
Correct |
20 ms |
460 KB |
Output is correct |
71 |
Correct |
20 ms |
460 KB |
Output is correct |
72 |
Correct |
13 ms |
504 KB |
Output is correct |
73 |
Correct |
12 ms |
508 KB |
Output is correct |
74 |
Correct |
20 ms |
460 KB |
Output is correct |
75 |
Correct |
19 ms |
460 KB |
Output is correct |
76 |
Correct |
22 ms |
460 KB |
Output is correct |
77 |
Correct |
24 ms |
516 KB |
Output is correct |
78 |
Correct |
22 ms |
460 KB |
Output is correct |
79 |
Correct |
127 ms |
18244 KB |
Output is correct |
80 |
Correct |
136 ms |
18140 KB |
Output is correct |
81 |
Correct |
131 ms |
18116 KB |
Output is correct |
82 |
Correct |
131 ms |
18124 KB |
Output is correct |
83 |
Correct |
116 ms |
18192 KB |
Output is correct |
84 |
Correct |
118 ms |
18236 KB |
Output is correct |
85 |
Correct |
115 ms |
18200 KB |
Output is correct |
86 |
Correct |
115 ms |
18284 KB |
Output is correct |
87 |
Correct |
195 ms |
848 KB |
Output is correct |
88 |
Correct |
187 ms |
832 KB |
Output is correct |
89 |
Correct |
187 ms |
868 KB |
Output is correct |
90 |
Correct |
186 ms |
836 KB |
Output is correct |
91 |
Correct |
41 ms |
496 KB |
Output is correct |
92 |
Correct |
43 ms |
552 KB |
Output is correct |
93 |
Correct |
32 ms |
456 KB |
Output is correct |
94 |
Correct |
17 ms |
524 KB |
Output is correct |
95 |
Correct |
19 ms |
460 KB |
Output is correct |
96 |
Correct |
22 ms |
560 KB |
Output is correct |
97 |
Correct |
20 ms |
528 KB |
Output is correct |
98 |
Correct |
19 ms |
460 KB |
Output is correct |