#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 3000;
const ll INF = 1e9;
struct Point { ll x, y; };
bool operator == (const Point &p, const Point &q) { return p.x==q.x && p.y==q.y; }
Point operator + (const Point &p, const Point &q) { return {p.x+q.x, p.y+q.y}; }
Point operator - (const Point &p, const Point &q) { return {p.x-q.x, p.y-q.y}; }
ll ccw(Point p, Point q) { return p.x*q.y-p.y*q.x; }
ll ccw(Point p, Point q1, Point q2) { return ccw(q1-p, q2-p); }
int N;
Point A[MAXN+10], P={INF, INF};
pii dp1[MAXN+10][MAXN+10], dp2[MAXN+10][MAXN+10];
pair<int, pii> ans;
int main()
{
int i, j, k;
scanf("%d", &N);
for(i=1; i<=N; i++) scanf("%lld%lld", &A[i].x, &A[i].y);
for(i=1; i<=N; i++) if(A[i].y<P.y) P=A[i];
for(i=1; i<=N; i++) if(A[i]==P) break;
for(; i<N; i++) swap(A[i], A[i+1]);
N--;
sort(A+1, A+N+1, [&](const Point &p, const Point &q) { return ccw(P, p, q)<0; });
for(i=1; i<=N; i++)
{
vector<int> L, R;
for(j=i+1; j<=N; j++) if(ccw(P, A[i], A[j])!=0) R.push_back(j), dp1[j][i+1]=dp2[j][i+1]={-987654321, 0};
for(j=1; j<i; j++) if(ccw(P, A[i], A[j])!=0) L.push_back(j);
sort(L.begin(), L.end(), [&](const int &p, const int &q) { return ccw(A[i]-A[p], A[i]-A[q])<0; });
sort(R.begin(), R.end(), [&](const int &p, const int &q) { return ccw(A[p]-A[i], A[q]-A[i])<0; });
pii now={2, i};
for(j=0, k=0; j<R.size(); j++)
{
for(; k<L.size() && ccw(A[i]-A[L[k]], A[R[j]]-A[i])<0; k++) now=max(now, {dp2[L[k]][i].first+1, L[k]});
dp1[i][R[j]]=max(dp1[i][R[j]], now);
}
now={-987654321, 0};
for(j=R.size()-1, k=L.size()-1; j>=0; j--)
{
for(; k>=0 && ccw(A[i]-A[L[k]], A[R[j]]-A[i])>0; k--) now=max(now, {dp1[L[k]][i].first+1, L[k]});
dp2[i][R[j]]=max(dp2[i][R[j]], now);
ans=max(ans, {dp2[i][R[j]].first, {i, R[j]}});
}
}
if(ans.first==0) return !printf("0\n");
vector<Point> V;
pii v=ans.second; int t=2;
V.push_back(P);
while(1)
{
V.push_back(A[v.second]);
if(v.first==v.second) break;
if(t==2)
{
v={dp2[v.first][v.second].second, v.first};
t=1;
}
else
{
v={dp1[v.first][v.second].second, v.first};
t=2;
}
}
printf("%d\n", V.size());
for(auto it : V) printf("%lld %lld\n", it.x, it.y);
}
Compilation message
footprint.cpp: In function 'int main()':
footprint.cpp:48:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0, k=0; j<R.size(); j++)
~^~~~~~~~~
footprint.cpp:50:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; k<L.size() && ccw(A[i]-A[L[k]], A[R[j]]-A[i])<0; k++) now=max(now, {dp2[L[k]][i].first+1, L[k]});
~^~~~~~~~~
footprint.cpp:82:25: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<Point>::size_type {aka long unsigned int}' [-Wformat=]
printf("%d\n", V.size());
~~~~~~~~^
footprint.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
footprint.cpp:30:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=N; i++) scanf("%lld%lld", &A[i].x, &A[i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
957 ms |
129412 KB |
Output is correct |
2 |
Correct |
985 ms |
131836 KB |
Output is correct |
3 |
Correct |
966 ms |
130552 KB |
Output is correct |
4 |
Correct |
982 ms |
132004 KB |
Output is correct |
5 |
Correct |
982 ms |
131064 KB |
Output is correct |
6 |
Correct |
998 ms |
131960 KB |
Output is correct |
7 |
Correct |
987 ms |
131448 KB |
Output is correct |
8 |
Correct |
988 ms |
132260 KB |
Output is correct |
9 |
Correct |
986 ms |
132488 KB |
Output is correct |
10 |
Correct |
990 ms |
132088 KB |
Output is correct |
11 |
Correct |
993 ms |
132092 KB |
Output is correct |
12 |
Correct |
999 ms |
132676 KB |
Output is correct |
13 |
Correct |
1028 ms |
134136 KB |
Output is correct |
14 |
Correct |
979 ms |
131964 KB |
Output is correct |
15 |
Correct |
985 ms |
130808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
380 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
380 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
12 ms |
3840 KB |
Output is correct |
22 |
Correct |
14 ms |
3840 KB |
Output is correct |
23 |
Correct |
13 ms |
3840 KB |
Output is correct |
24 |
Correct |
15 ms |
4224 KB |
Output is correct |
25 |
Correct |
14 ms |
4224 KB |
Output is correct |
26 |
Correct |
14 ms |
4096 KB |
Output is correct |
27 |
Correct |
14 ms |
4096 KB |
Output is correct |
28 |
Correct |
14 ms |
4096 KB |
Output is correct |
29 |
Correct |
14 ms |
4096 KB |
Output is correct |
30 |
Correct |
14 ms |
4096 KB |
Output is correct |
31 |
Correct |
15 ms |
4352 KB |
Output is correct |
32 |
Correct |
19 ms |
4224 KB |
Output is correct |
33 |
Correct |
11 ms |
4224 KB |
Output is correct |
34 |
Correct |
13 ms |
4224 KB |
Output is correct |
35 |
Correct |
10 ms |
4096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
957 ms |
129412 KB |
Output is correct |
2 |
Correct |
985 ms |
131836 KB |
Output is correct |
3 |
Correct |
966 ms |
130552 KB |
Output is correct |
4 |
Correct |
982 ms |
132004 KB |
Output is correct |
5 |
Correct |
982 ms |
131064 KB |
Output is correct |
6 |
Correct |
998 ms |
131960 KB |
Output is correct |
7 |
Correct |
987 ms |
131448 KB |
Output is correct |
8 |
Correct |
988 ms |
132260 KB |
Output is correct |
9 |
Correct |
986 ms |
132488 KB |
Output is correct |
10 |
Correct |
990 ms |
132088 KB |
Output is correct |
11 |
Correct |
993 ms |
132092 KB |
Output is correct |
12 |
Correct |
999 ms |
132676 KB |
Output is correct |
13 |
Correct |
1028 ms |
134136 KB |
Output is correct |
14 |
Correct |
979 ms |
131964 KB |
Output is correct |
15 |
Correct |
985 ms |
130808 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
380 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
6 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
12 ms |
3840 KB |
Output is correct |
37 |
Correct |
14 ms |
3840 KB |
Output is correct |
38 |
Correct |
13 ms |
3840 KB |
Output is correct |
39 |
Correct |
15 ms |
4224 KB |
Output is correct |
40 |
Correct |
14 ms |
4224 KB |
Output is correct |
41 |
Correct |
14 ms |
4096 KB |
Output is correct |
42 |
Correct |
14 ms |
4096 KB |
Output is correct |
43 |
Correct |
14 ms |
4096 KB |
Output is correct |
44 |
Correct |
14 ms |
4096 KB |
Output is correct |
45 |
Correct |
14 ms |
4096 KB |
Output is correct |
46 |
Correct |
15 ms |
4352 KB |
Output is correct |
47 |
Correct |
19 ms |
4224 KB |
Output is correct |
48 |
Correct |
11 ms |
4224 KB |
Output is correct |
49 |
Correct |
13 ms |
4224 KB |
Output is correct |
50 |
Correct |
10 ms |
4096 KB |
Output is correct |
51 |
Correct |
1025 ms |
131784 KB |
Output is correct |
52 |
Correct |
1033 ms |
132076 KB |
Output is correct |
53 |
Correct |
1068 ms |
133728 KB |
Output is correct |
54 |
Correct |
1195 ms |
141952 KB |
Output is correct |
55 |
Correct |
1203 ms |
141824 KB |
Output is correct |
56 |
Correct |
1196 ms |
141904 KB |
Output is correct |
57 |
Correct |
1203 ms |
141852 KB |
Output is correct |
58 |
Correct |
1192 ms |
141696 KB |
Output is correct |
59 |
Correct |
1187 ms |
141820 KB |
Output is correct |
60 |
Correct |
1254 ms |
141944 KB |
Output is correct |
61 |
Correct |
1157 ms |
141816 KB |
Output is correct |
62 |
Correct |
1159 ms |
142072 KB |
Output is correct |
63 |
Correct |
593 ms |
141796 KB |
Output is correct |
64 |
Correct |
601 ms |
141836 KB |
Output is correct |
65 |
Correct |
610 ms |
141920 KB |
Output is correct |
66 |
Correct |
796 ms |
141820 KB |
Output is correct |
67 |
Correct |
795 ms |
141672 KB |
Output is correct |
68 |
Correct |
836 ms |
141816 KB |
Output is correct |