#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; bool blue;
int id;
pt() {
x = 0; y = 0; blue = 0; id = 0;
}
pt(ll x, ll y): x(x), y(y), blue(0), id(0) {}
pt(ll x, ll y, bool blue, int id): x(x), y(y), blue(blue), 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 && blue == r.blue && 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, pt lowest) {
points.erase(find(ALL(points), lowest));
sort(ALL(points), [&] (pt l, pt r) {
// sort clockwise
return orient(lowest, l, r) < 0;
});
//printf("%lld %lld %d\n", lowest.x, lowest.y, lowest.id);
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[3];
void split1(vector<pt> points, pt lowest) {
int cnt = 0;
pt f, s;
int i = 0;
REP (j, 0, 3) {
res[j].clear();
}
for (pt point : points) {
if (point.blue) {
cnt -= 2;
} else {
cnt++;
}
if (cnt == 1 && i == 0 && !point.blue) {
f = point;
i++;
} else if (cnt == 2 && i == 1 && !point.blue) {
s = point;
i++;
} else {
res[i].pb(point);
}
}
ans[lowest.id] = MP(f.id, s.id);
vector<pt> tmp[3];
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, 3) {
res[j].clear();
}
int cnt = 0;
for (pt point : points) {
if (point.blue) {
cnt -= 2;
} else {
cnt++;
}
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[2];
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;
}
pt lowest;
lowest.y = INF;
REP (i, 0, points.size()) {
if (points[i].y < lowest.y) {
lowest = points[i];
}
}
order(points, lowest);
if (lowest.blue) {
split1(points, lowest);
} else if (points[0].blue) {
points.pb(lowest);
lowest = points[0];
order(points, lowest);
split1(points, lowest);
} else if (points.back().blue) {
pt tmp = points.back();
points.pb(lowest);
lowest = tmp;
order(points, lowest);
split1(points, lowest);
} else {
split2(points, lowest);
}
}
int main() {
scanf("%d", &n);
REP (i, 0, n) {
pt temp;
scanf("%lld%lld", &temp.x, &temp.y);
temp.id = i;
temp.blue = 1;
points.pb(temp);
}
REP (i, n, 3 * n) {
pt temp;
scanf("%lld%lld", &temp.x, &temp.y);
temp.id = i;
temp.blue = 0;
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 order(std::vector<pt>&, pt)':
laser.cpp:6:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
6 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
61 | REP (i, 0, points.size()) {
| ~~~~~~~~~~~~~~~~~~~
laser.cpp:61:2: note: in expansion of macro 'REP'
61 | REP (i, 0, points.size()) {
| ^~~
laser.cpp: In function 'void solve(std::vector<pt>)':
laser.cpp:6:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
6 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
138 | REP (i, 0, points.size()) {
| ~~~~~~~~~~~~~~~~~~~
laser.cpp:138:2: note: in expansion of macro 'REP'
138 | REP (i, 0, points.size()) {
| ^~~
laser.cpp: In function 'int main()':
laser.cpp:163:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
163 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
laser.cpp:166:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
166 | scanf("%lld%lld", &temp.x, &temp.y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
laser.cpp:173:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
173 | 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 |
300 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 |
300 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
1 ms |
420 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
428 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
3 ms |
1356 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
3 ms |
844 KB |
Output is correct |
14 |
Correct |
3 ms |
1356 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 |
300 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 |
300 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
2 ms |
640 KB |
Output is correct |
26 |
Correct |
1 ms |
420 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
428 KB |
Output is correct |
29 |
Correct |
1 ms |
588 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
588 KB |
Output is correct |
33 |
Correct |
1 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
3 ms |
1356 KB |
Output is correct |
36 |
Correct |
1 ms |
716 KB |
Output is correct |
37 |
Correct |
3 ms |
844 KB |
Output is correct |
38 |
Correct |
3 ms |
1356 KB |
Output is correct |
39 |
Correct |
2 ms |
716 KB |
Output is correct |
40 |
Correct |
2 ms |
684 KB |
Output is correct |
41 |
Correct |
1 ms |
460 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Correct |
2 ms |
556 KB |
Output is correct |
44 |
Correct |
2 ms |
552 KB |
Output is correct |
45 |
Correct |
2 ms |
588 KB |
Output is correct |
46 |
Correct |
2 ms |
588 KB |
Output is correct |
47 |
Correct |
1 ms |
424 KB |
Output is correct |
48 |
Correct |
2 ms |
556 KB |
Output is correct |
49 |
Correct |
2 ms |
844 KB |
Output is correct |
50 |
Correct |
2 ms |
684 KB |
Output is correct |
51 |
Correct |
2 ms |
1228 KB |
Output is correct |
52 |
Correct |
2 ms |
1320 KB |
Output is correct |
53 |
Correct |
2 ms |
1356 KB |
Output is correct |
54 |
Correct |
3 ms |
1356 KB |
Output is correct |
55 |
Correct |
2 ms |
1320 KB |
Output is correct |
56 |
Correct |
2 ms |
1316 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
460 KB |
Output is correct |
59 |
Correct |
1 ms |
428 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
2 ms |
460 KB |
Output is correct |
62 |
Correct |
1 ms |
428 KB |
Output is correct |
63 |
Correct |
1 ms |
428 KB |
Output is correct |
64 |
Correct |
1 ms |
588 KB |
Output is correct |
65 |
Correct |
2 ms |
460 KB |
Output is correct |
66 |
Correct |
2 ms |
588 KB |
Output is correct |
67 |
Correct |
2 ms |
588 KB |
Output is correct |
68 |
Correct |
1 ms |
588 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 |
300 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 |
300 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
2 ms |
640 KB |
Output is correct |
26 |
Correct |
1 ms |
420 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
428 KB |
Output is correct |
29 |
Correct |
1 ms |
588 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
588 KB |
Output is correct |
33 |
Correct |
1 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
3 ms |
1356 KB |
Output is correct |
36 |
Correct |
1 ms |
716 KB |
Output is correct |
37 |
Correct |
3 ms |
844 KB |
Output is correct |
38 |
Correct |
3 ms |
1356 KB |
Output is correct |
39 |
Correct |
2 ms |
716 KB |
Output is correct |
40 |
Correct |
2 ms |
684 KB |
Output is correct |
41 |
Correct |
1 ms |
460 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Correct |
2 ms |
556 KB |
Output is correct |
44 |
Correct |
2 ms |
552 KB |
Output is correct |
45 |
Correct |
2 ms |
588 KB |
Output is correct |
46 |
Correct |
2 ms |
588 KB |
Output is correct |
47 |
Correct |
1 ms |
424 KB |
Output is correct |
48 |
Correct |
2 ms |
556 KB |
Output is correct |
49 |
Correct |
2 ms |
844 KB |
Output is correct |
50 |
Correct |
2 ms |
684 KB |
Output is correct |
51 |
Correct |
2 ms |
1228 KB |
Output is correct |
52 |
Correct |
2 ms |
1320 KB |
Output is correct |
53 |
Correct |
2 ms |
1356 KB |
Output is correct |
54 |
Correct |
3 ms |
1356 KB |
Output is correct |
55 |
Correct |
2 ms |
1320 KB |
Output is correct |
56 |
Correct |
2 ms |
1316 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
460 KB |
Output is correct |
59 |
Correct |
1 ms |
428 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
2 ms |
460 KB |
Output is correct |
62 |
Correct |
1 ms |
428 KB |
Output is correct |
63 |
Correct |
1 ms |
428 KB |
Output is correct |
64 |
Correct |
1 ms |
588 KB |
Output is correct |
65 |
Correct |
2 ms |
460 KB |
Output is correct |
66 |
Correct |
2 ms |
588 KB |
Output is correct |
67 |
Correct |
2 ms |
588 KB |
Output is correct |
68 |
Correct |
1 ms |
588 KB |
Output is correct |
69 |
Correct |
30 ms |
15432 KB |
Output is correct |
70 |
Correct |
20 ms |
10060 KB |
Output is correct |
71 |
Correct |
34 ms |
15692 KB |
Output is correct |
72 |
Correct |
21 ms |
9280 KB |
Output is correct |
73 |
Correct |
17 ms |
8264 KB |
Output is correct |
74 |
Correct |
23 ms |
10680 KB |
Output is correct |
75 |
Correct |
27 ms |
10728 KB |
Output is correct |
76 |
Correct |
29 ms |
11844 KB |
Output is correct |
77 |
Correct |
19 ms |
6380 KB |
Output is correct |
78 |
Correct |
20 ms |
8960 KB |
Output is correct |
79 |
Runtime error |
161 ms |
65540 KB |
Execution killed with signal 9 |
80 |
Halted |
0 ms |
0 KB |
- |