#include <bits/stdc++.h>
#define eb emplace_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
ll operator * (const pll &a, const pll &b) { return a.fi * b.se - b.fi * a.se; }
ll ccw(const pll &a, const pll &b, const pll &c) { return a*b + b*c + c*a; }
int D[3005][3005], RD[3005][3005];
int E[3005][3005], RE[3005][3005];
int NV[3005], NVn;
int PV[3005], PVn;
pll P[3005];
int N;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N;
for(int i = 0; i < N; i++) {
cin >> P[i].fi >> P[i].se;
if(P[i].se < P[0].se) swap(P[0], P[i]);
}
N--;
sort(P+1, P+N+1, [&](const pll &a, const pll &b) { return ccw(P[0], a, b) > 0; });
for(int i = 1; i <= N; i++) {
D[i][0] = 2;
NVn = PVn = 0;
{
int k = i+1;
for(; k <= N && !ccw(P[0], P[i], P[k]); k++);
for(; k <= N; k++) NV[NVn++] = k;
}
{
PV[PVn++] = 0;
int j = i-1;
for(; j && !ccw(P[0], P[i], P[j]); j--);
for(; j; j--) PV[PVn++] = j;
}
sort(NV, NV+NVn, [&](int a, int b) { return ccw(P[i], P[a], P[b]) > 0; });
sort(PV, PV+PVn, [&](int a, int b) { return ccw(P[i], P[a], P[b]) > 0; });
for(int ki = 0, k, ji = 0, j, mx = 0, mxj; ki < NVn; ki++) {
k = NV[ki];
for(; ji < PVn; ji++) {
j = PV[ji];
if(ccw(P[j], P[i], P[k]) <= 0) break;
if(mx < D[i][j]) {
mx = D[i][j];
mxj = j;
}
}
if(mx) {
E[k][i] = mx + 1;
RE[k][i] = mxj;
}
}
for(int ki = NVn-1, k, ji = PVn-1, j, mx = 0, mxj; 0 <= ki; ki--) {
k = NV[ki];
for(; 0 <= ji; ji--) {
j = PV[ji];
if(ccw(P[j], P[i], P[k]) >= 0) break;
if(mx < E[i][j]) {
mx = E[i][j];
mxj = j;
}
}
if(mx) {
D[k][i] = mx + 1;
RD[k][i] = mxj;
}
}
}
{
int Ans = 0, I, J;
for(int i = N; i; i--) for(int j = i-1; j; j--)
if(Ans < D[i][j]) {
Ans = D[i][j];
I = i; J = j;
}
if(Ans < 4) { puts("0"); exit(0); }
cout << Ans << '\n';
vector<int> V;
for(int t = 0; 2 < Ans; Ans--, t ^= 1) {
V.eb(I);
I = (t ? RE : RD)[I][J];
swap(I, J);
}
V.eb(I); V.eb(J);
reverse(V.begin(), V.end());
for(int v : V) cout << P[v].fi << ' ' << P[v].se << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1066 ms |
98524 KB |
Output is correct |
2 |
Correct |
1138 ms |
100932 KB |
Output is correct |
3 |
Correct |
1113 ms |
99704 KB |
Output is correct |
4 |
Correct |
1123 ms |
100984 KB |
Output is correct |
5 |
Correct |
1110 ms |
100000 KB |
Output is correct |
6 |
Correct |
1172 ms |
101112 KB |
Output is correct |
7 |
Correct |
1131 ms |
100480 KB |
Output is correct |
8 |
Correct |
1123 ms |
101256 KB |
Output is correct |
9 |
Correct |
1127 ms |
101412 KB |
Output is correct |
10 |
Correct |
1115 ms |
101276 KB |
Output is correct |
11 |
Correct |
1126 ms |
101248 KB |
Output is correct |
12 |
Correct |
1150 ms |
101752 KB |
Output is correct |
13 |
Correct |
1149 ms |
103024 KB |
Output is correct |
14 |
Correct |
1129 ms |
101240 KB |
Output is correct |
15 |
Correct |
1092 ms |
99960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
0 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
0 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
11 ms |
5408 KB |
Output is correct |
22 |
Correct |
11 ms |
5504 KB |
Output is correct |
23 |
Correct |
10 ms |
5376 KB |
Output is correct |
24 |
Correct |
12 ms |
5888 KB |
Output is correct |
25 |
Correct |
12 ms |
5888 KB |
Output is correct |
26 |
Correct |
11 ms |
5888 KB |
Output is correct |
27 |
Correct |
11 ms |
5760 KB |
Output is correct |
28 |
Correct |
11 ms |
5760 KB |
Output is correct |
29 |
Correct |
11 ms |
5760 KB |
Output is correct |
30 |
Correct |
11 ms |
5888 KB |
Output is correct |
31 |
Correct |
12 ms |
5888 KB |
Output is correct |
32 |
Correct |
12 ms |
5888 KB |
Output is correct |
33 |
Correct |
6 ms |
4352 KB |
Output is correct |
34 |
Correct |
6 ms |
4352 KB |
Output is correct |
35 |
Correct |
6 ms |
4352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1066 ms |
98524 KB |
Output is correct |
2 |
Correct |
1138 ms |
100932 KB |
Output is correct |
3 |
Correct |
1113 ms |
99704 KB |
Output is correct |
4 |
Correct |
1123 ms |
100984 KB |
Output is correct |
5 |
Correct |
1110 ms |
100000 KB |
Output is correct |
6 |
Correct |
1172 ms |
101112 KB |
Output is correct |
7 |
Correct |
1131 ms |
100480 KB |
Output is correct |
8 |
Correct |
1123 ms |
101256 KB |
Output is correct |
9 |
Correct |
1127 ms |
101412 KB |
Output is correct |
10 |
Correct |
1115 ms |
101276 KB |
Output is correct |
11 |
Correct |
1126 ms |
101248 KB |
Output is correct |
12 |
Correct |
1150 ms |
101752 KB |
Output is correct |
13 |
Correct |
1149 ms |
103024 KB |
Output is correct |
14 |
Correct |
1129 ms |
101240 KB |
Output is correct |
15 |
Correct |
1092 ms |
99960 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
0 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
11 ms |
5408 KB |
Output is correct |
37 |
Correct |
11 ms |
5504 KB |
Output is correct |
38 |
Correct |
10 ms |
5376 KB |
Output is correct |
39 |
Correct |
12 ms |
5888 KB |
Output is correct |
40 |
Correct |
12 ms |
5888 KB |
Output is correct |
41 |
Correct |
11 ms |
5888 KB |
Output is correct |
42 |
Correct |
11 ms |
5760 KB |
Output is correct |
43 |
Correct |
11 ms |
5760 KB |
Output is correct |
44 |
Correct |
11 ms |
5760 KB |
Output is correct |
45 |
Correct |
11 ms |
5888 KB |
Output is correct |
46 |
Correct |
12 ms |
5888 KB |
Output is correct |
47 |
Correct |
12 ms |
5888 KB |
Output is correct |
48 |
Correct |
6 ms |
4352 KB |
Output is correct |
49 |
Correct |
6 ms |
4352 KB |
Output is correct |
50 |
Correct |
6 ms |
4352 KB |
Output is correct |
51 |
Correct |
1106 ms |
100756 KB |
Output is correct |
52 |
Correct |
1112 ms |
101240 KB |
Output is correct |
53 |
Correct |
1145 ms |
102828 KB |
Output is correct |
54 |
Correct |
1313 ms |
110936 KB |
Output is correct |
55 |
Correct |
1305 ms |
110968 KB |
Output is correct |
56 |
Correct |
1355 ms |
110860 KB |
Output is correct |
57 |
Correct |
1323 ms |
110712 KB |
Output is correct |
58 |
Correct |
1308 ms |
110840 KB |
Output is correct |
59 |
Correct |
1344 ms |
110944 KB |
Output is correct |
60 |
Correct |
1312 ms |
110968 KB |
Output is correct |
61 |
Correct |
1306 ms |
110856 KB |
Output is correct |
62 |
Correct |
1306 ms |
110960 KB |
Output is correct |
63 |
Correct |
593 ms |
67772 KB |
Output is correct |
64 |
Correct |
595 ms |
67832 KB |
Output is correct |
65 |
Correct |
603 ms |
67864 KB |
Output is correct |
66 |
Correct |
952 ms |
110840 KB |
Output is correct |
67 |
Correct |
968 ms |
110864 KB |
Output is correct |
68 |
Correct |
983 ms |
110840 KB |
Output is correct |