#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define N 3005
using namespace std;
typedef long long ll;
struct st{
ll x, y, id;
} o, a[N];
ll n, ans, d1[N][N], d2[N][N], h1[N][N], h2[N][N];
vector<st> lt, rt;
ll ccw(st p, st q, st r) {
return p.x * q.y + q.x * r.y + r.x * p.y - q.x * p.y - r.x * q.y - p.x * r.y;
}
bool cmp(st p, st q) {return ccw(o, p, q) > 0;}
bool cmpmn(st p, st q) {
if (p.y != q.y) return p.y < q.y;
else return p.x < q.x;
}
void print(ll p, ll q, ll r) {
if (p == 0) {printf("%lld %lld\n", a[p].x, a[p].y); return;}
if (r == 1) print(q, h1[p][q], 2);
else print(q, h2[p][q], 1);
printf("%lld %lld\n", a[p].x, a[p].y);
}
int main()
{
ll i, j, k;
cin >> n;
for (i = 0; i < n; i++) {
scanf("%lld %lld", &a[i].x, &a[i].y);
}
sort(a, a + n, cmpmn);
o = a[0];
sort(a + 1, a + n, cmp);
for (i = 0; i < n; i++) a[i].id = i;
for (i = 1; i < n; i++) d1[i][0] = 2;
for (i = 1; i < n; i++) {
lt.clear(); rt.clear();
for (j = 0; j < i; j++) rt.push_back(a[j]);
for (j = i + 1; j < n; j++) lt.push_back(a[j]);
o = a[i];
sort(lt.begin(), lt.end(), cmp);
sort(rt.begin(), rt.end(), cmp);
ll mx = -1e9, mi = 0;
ll I = a[i].id;
for (j = 0, k = 0; j < lt.size(); j++) {
ll J = lt[j].id;
for (; k < rt.size(); k++) {
ll K = rt[k].id;
if (ccw(rt[k], a[i], lt[j]) <= 0) break;
if (d1[I][K] + 1 > mx) mx = d1[I][K] + 1, mi = K;
}
d2[J][I] = mx;
h2[J][I] = mi;
}
mx = -1e9, mi = 0;
for (j = (ll)lt.size() - 1, k = (ll)rt.size() - 1; j >= 0; j--) {
ll J = lt[j].id;
for (; k >= 0; k--) {
ll K = rt[k].id;
if (ccw(rt[k], a[i], lt[j]) >= 0) break;
if (d2[I][K] + 1 > mx) mx = d2[I][K] + 1, mi = K;
}
d1[J][I] = mx;
h1[J][I] = mi;
}
}
for (i = 0; i < n; i++) for (j = 0; j < i; j++) ans = max(ans, d1[i][j]);
if (ans <= 3) {cout << '0'; return 0;}
cout << ans << endl;
for (i = 0; i < n; i++) for (j = 0; j < i; j++) if (d1[i][j] == ans) {print(i, j, 1); return 0;}
return 0;
}
Compilation message
footprint.cpp: In function 'int main()':
footprint.cpp:56:24: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (j = 0, k = 0; j < lt.size(); j++) {
| ~~^~~~~~~~~~~
footprint.cpp:58:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (; k < rt.size(); k++) {
| ~~^~~~~~~~~~~
footprint.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
38 | scanf("%lld %lld", &a[i].x, &a[i].y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1371 ms |
160572 KB |
Output is correct |
2 |
Correct |
1428 ms |
165516 KB |
Output is correct |
3 |
Correct |
1408 ms |
162924 KB |
Output is correct |
4 |
Correct |
1437 ms |
165840 KB |
Output is correct |
5 |
Correct |
1402 ms |
164072 KB |
Output is correct |
6 |
Correct |
1433 ms |
165752 KB |
Output is correct |
7 |
Correct |
1434 ms |
164660 KB |
Output is correct |
8 |
Correct |
1428 ms |
166200 KB |
Output is correct |
9 |
Correct |
1442 ms |
166756 KB |
Output is correct |
10 |
Correct |
1442 ms |
166128 KB |
Output is correct |
11 |
Correct |
1441 ms |
165908 KB |
Output is correct |
12 |
Correct |
1447 ms |
167060 KB |
Output is correct |
13 |
Correct |
1464 ms |
169892 KB |
Output is correct |
14 |
Correct |
1453 ms |
165916 KB |
Output is correct |
15 |
Correct |
1412 ms |
163388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1371 ms |
160572 KB |
Output is correct |
2 |
Correct |
1428 ms |
165516 KB |
Output is correct |
3 |
Correct |
1408 ms |
162924 KB |
Output is correct |
4 |
Correct |
1437 ms |
165840 KB |
Output is correct |
5 |
Correct |
1402 ms |
164072 KB |
Output is correct |
6 |
Correct |
1433 ms |
165752 KB |
Output is correct |
7 |
Correct |
1434 ms |
164660 KB |
Output is correct |
8 |
Correct |
1428 ms |
166200 KB |
Output is correct |
9 |
Correct |
1442 ms |
166756 KB |
Output is correct |
10 |
Correct |
1442 ms |
166128 KB |
Output is correct |
11 |
Correct |
1441 ms |
165908 KB |
Output is correct |
12 |
Correct |
1447 ms |
167060 KB |
Output is correct |
13 |
Correct |
1464 ms |
169892 KB |
Output is correct |
14 |
Correct |
1453 ms |
165916 KB |
Output is correct |
15 |
Correct |
1412 ms |
163388 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |