#include <bits/stdc++.h>
using namespace std;
#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 3005
struct pt {
ll x, y; int color;
int id;
pt() {
x = 0; y = 0; color = 0; id = 0;
}
pt(ll x, ll y): x(x), y(y), color(0), id(0) {}
pt(ll x, ll y, int color, int id): x(x), y(y), color(color), id(id) {}
pt operator-(const pt& other) const {
return pt(x - other.x, y - other.y);
}
bool operator==(const pt& r) const {
return x == r.x && y == r.y && color == r.color && id == r.id;
}
};
ll cross(pt a, pt b) {
return a.x * b.y - a.y * b.x;
}
// positive if c is to the right/top of line ab
ll orient(pt a, pt b, pt c) {
return cross(b - a, c - a);
}
int n;
vector<pt> points;
ii ans[MAXN];
void order(vector<pt>& points) {
sort(points.begin() + 1, points.end(), [&] (pt l, pt r) {
// sort clockwise
return orient(points[0], l, r) < 0;
});
//REP (i, 0, points.size()) {
//printf(" %lld %lld %d\n", points[i].x, points[i].y, points[i].id);
//}
}
void solve(vector<pt> points);
vector<pt> res[5];
void split1(vector<pt> points, pt lowest) {
int cnt = 0;
pt f, s;
int i = 0;
REP (j, 0, 5) {
res[j].clear();
}
for (pt point : points) {
cnt += point.color;
if (cnt == -1 && i == 0 && point.color == -1) {
f = point;
i++;
} else if (cnt == -2 && i == 1 && point.color == -1) {
s = point;
i++;
} else {
res[i].pb(point);
}
}
ans[lowest.id] = MP(f.id, s.id);
vector<pt> tmp[5];
REP (j, 0, 3) {
tmp[j] = res[j];
}
REP (j, 0, 3) {
solve(tmp[j]);
}
}
void split2(vector<pt> points, pt lowest) {
int i = 0;
REP (j, 0, 5) {
res[j].clear();
}
int cnt = 0;
for (pt point : points) {
cnt += point.color;
res[i].pb(point);
if (i == 0 && cnt == 0) {
i++;
res[i].pb(lowest);
} else if (i == 0 && cnt == 1) {
res[i].pb(lowest);
i++;
}
}
vector<pt> tmp[5];
REP (j, 0, 2) {
tmp[j] = res[j];
}
REP (j, 0, 2) {
solve(tmp[j]);
}
}
void solve(vector<pt> points) {
if (points.size() == 0) {
return;
}
sort(ALL(points), [&] (pt l, pt r) {
return l.y < r.y;
});
order(points);
if (points[0].color == 2 || points[1].color == 2 || points.back().color == 2) {
if (points[1].color == 2) {
swap(points[1], points[0]);
} else if (points.back().color == 2) {
swap(points[points.size() - 1], points[0]);
}
order(points);
int cnt = 0;
pt f, s;
int i = 0;
vector<pt> res[5];
for (int j = 1; j < points.size(); j++) {
pt point = points[j];
cnt += point.color;
if (cnt == -1 && i == 0 && point.color == -1) {
f = point;
i++;
} else if (cnt == -2 && i == 1 && point.color == -1) {
s = point;
i++;
} else {
res[i].pb(point);
}
}
ans[points[0].id] = MP(f.id, s.id);
REP (j, 0, 3) {
solve(res[j]);
}
} else {
int i = 0;
int cnt = 0;
vector<pt> res[5];
for (int j = 1; j < points.size(); j++) {
pt point = points[j];
cnt += point.color;
res[i].pb(point);
if (i == 0 && cnt == 0) {
i++;
res[i].pb(points[0]);
} else if (i == 0 && cnt == 1) {
res[i].pb(points[0]);
i++;
}
}
REP (j, 0, 2) {
solve(res[j]);
}
}
}
int main() {
scanf("%d", &n);
REP (i, 0, n) {
pt temp;
scanf("%lld%lld", &temp.x, &temp.y);
temp.id = i;
temp.color = 2;
points.pb(temp);
}
REP (i, n, 3 * n) {
pt temp;
scanf("%lld%lld", &temp.x, &temp.y);
temp.id = i;
temp.color = -1;
points.pb(temp);
}
solve(points);
REP (i, 0, n) {
printf("%d %d\n", ans[i].FI - n + 1, ans[i].SE - n + 1);
}
return 0;
}
Compilation message
laser.cpp: In function 'void solve(std::vector<pt>)':
laser.cpp:141:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
141 | for (int j = 1; j < points.size(); j++) {
| ~~^~~~~~~~~~~~~~~
laser.cpp:162:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
162 | for (int j = 1; j < points.size(); j++) {
| ~~^~~~~~~~~~~~~~~
laser.cpp: In function 'int main()':
laser.cpp:181:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
181 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
laser.cpp:184:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
184 | scanf("%lld%lld", &temp.x, &temp.y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
laser.cpp:191:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
191 | scanf("%lld%lld", &temp.x, &temp.y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
204 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 |
204 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 |
204 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 |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
1100 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
736 KB |
Output is correct |
14 |
Correct |
3 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
204 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 |
204 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 |
204 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 |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
236 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
4 ms |
1100 KB |
Output is correct |
36 |
Correct |
2 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
736 KB |
Output is correct |
38 |
Correct |
3 ms |
1100 KB |
Output is correct |
39 |
Correct |
2 ms |
460 KB |
Output is correct |
40 |
Correct |
2 ms |
588 KB |
Output is correct |
41 |
Correct |
2 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
2 ms |
460 KB |
Output is correct |
44 |
Correct |
2 ms |
460 KB |
Output is correct |
45 |
Correct |
2 ms |
460 KB |
Output is correct |
46 |
Correct |
2 ms |
460 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
2 ms |
460 KB |
Output is correct |
49 |
Correct |
2 ms |
716 KB |
Output is correct |
50 |
Correct |
2 ms |
588 KB |
Output is correct |
51 |
Correct |
4 ms |
844 KB |
Output is correct |
52 |
Correct |
3 ms |
716 KB |
Output is correct |
53 |
Correct |
2 ms |
716 KB |
Output is correct |
54 |
Correct |
3 ms |
716 KB |
Output is correct |
55 |
Correct |
2 ms |
716 KB |
Output is correct |
56 |
Correct |
2 ms |
716 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
2 ms |
460 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 |
460 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
2 ms |
460 KB |
Output is correct |
65 |
Correct |
2 ms |
460 KB |
Output is correct |
66 |
Correct |
2 ms |
460 KB |
Output is correct |
67 |
Correct |
2 ms |
588 KB |
Output is correct |
68 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
204 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 |
204 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 |
204 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 |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
236 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
4 ms |
1100 KB |
Output is correct |
36 |
Correct |
2 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
736 KB |
Output is correct |
38 |
Correct |
3 ms |
1100 KB |
Output is correct |
39 |
Correct |
2 ms |
460 KB |
Output is correct |
40 |
Correct |
2 ms |
588 KB |
Output is correct |
41 |
Correct |
2 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
2 ms |
460 KB |
Output is correct |
44 |
Correct |
2 ms |
460 KB |
Output is correct |
45 |
Correct |
2 ms |
460 KB |
Output is correct |
46 |
Correct |
2 ms |
460 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
2 ms |
460 KB |
Output is correct |
49 |
Correct |
2 ms |
716 KB |
Output is correct |
50 |
Correct |
2 ms |
588 KB |
Output is correct |
51 |
Correct |
4 ms |
844 KB |
Output is correct |
52 |
Correct |
3 ms |
716 KB |
Output is correct |
53 |
Correct |
2 ms |
716 KB |
Output is correct |
54 |
Correct |
3 ms |
716 KB |
Output is correct |
55 |
Correct |
2 ms |
716 KB |
Output is correct |
56 |
Correct |
2 ms |
716 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
2 ms |
460 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 |
460 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
2 ms |
460 KB |
Output is correct |
65 |
Correct |
2 ms |
460 KB |
Output is correct |
66 |
Correct |
2 ms |
460 KB |
Output is correct |
67 |
Correct |
2 ms |
588 KB |
Output is correct |
68 |
Correct |
2 ms |
460 KB |
Output is correct |
69 |
Correct |
50 ms |
10568 KB |
Output is correct |
70 |
Correct |
31 ms |
6904 KB |
Output is correct |
71 |
Correct |
55 ms |
11444 KB |
Output is correct |
72 |
Correct |
31 ms |
7032 KB |
Output is correct |
73 |
Correct |
24 ms |
5068 KB |
Output is correct |
74 |
Correct |
21 ms |
3788 KB |
Output is correct |
75 |
Correct |
41 ms |
7704 KB |
Output is correct |
76 |
Correct |
41 ms |
8260 KB |
Output is correct |
77 |
Correct |
23 ms |
4364 KB |
Output is correct |
78 |
Correct |
29 ms |
5828 KB |
Output is correct |
79 |
Correct |
219 ms |
48196 KB |
Output is correct |
80 |
Correct |
213 ms |
46144 KB |
Output is correct |
81 |
Correct |
219 ms |
47556 KB |
Output is correct |
82 |
Correct |
160 ms |
37296 KB |
Output is correct |
83 |
Correct |
170 ms |
37428 KB |
Output is correct |
84 |
Correct |
168 ms |
37540 KB |
Output is correct |
85 |
Correct |
170 ms |
37452 KB |
Output is correct |
86 |
Correct |
168 ms |
37408 KB |
Output is correct |
87 |
Correct |
38 ms |
7736 KB |
Output is correct |
88 |
Correct |
38 ms |
7368 KB |
Output is correct |
89 |
Correct |
61 ms |
16708 KB |
Output is correct |
90 |
Correct |
17 ms |
3020 KB |
Output is correct |
91 |
Correct |
28 ms |
5552 KB |
Output is correct |
92 |
Correct |
27 ms |
5100 KB |
Output is correct |
93 |
Correct |
20 ms |
3728 KB |
Output is correct |
94 |
Correct |
33 ms |
7748 KB |
Output is correct |
95 |
Correct |
23 ms |
4404 KB |
Output is correct |
96 |
Correct |
20 ms |
3692 KB |
Output is correct |
97 |
Correct |
23 ms |
3916 KB |
Output is correct |
98 |
Correct |
20 ms |
3532 KB |
Output is correct |