#include <bits/stdc++.h>
#define entire(X) X.begin(),X.end()
#define LAMB [](point const &a, point const &b)->bool
#define LAMBI [&j](int const &a, int const &b)->bool
using namespace std; typedef long long ll;
void OJize(){cin.tie(NULL); ios_base::sync_with_stdio(false);}
struct point{
ll x, y;
point(ll x, ll y): x{x}, y{y} {}
};
ostream &operator<<(ostream &os, point const &p){
return os << p.x << ' ' << p.y;
}
// positive -> ccw; negative -> cw; 0 -> collinear
ll ccw(point a, point b, point c){
return (b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x);
}
int dp[2][3003][3003];
int prv[2][3003][3003];
vector<point> pnts;
int main(){OJize();
int n; cin>>n;
for(int i=0; i<n; i++){
ll x, y; cin>>x>>y;
pnts.push_back(point(x, y));
}
sort(entire(pnts), LAMB{return a.y < b.y;});
sort(pnts.begin()+1, pnts.end(), LAMB{return ccw(pnts[0], a, b) > 0;});
// base case
for(int i=1; i<n; i++) dp[0][0][i] = 2; // 0 = heel
// update
for(int j=1; j<n-1; j++){
vector<int> bef, aft;
for(int i=0; i<j; i++)
if(!i || ccw(pnts[0], pnts[i], pnts[j])) bef.push_back(i);
for(int k=j+1; k<n; k++)
if(ccw(pnts[0], pnts[j], pnts[k])) aft.push_back(k);
sort(entire(bef), LAMBI{return ccw(pnts[j], pnts[a], pnts[b]) > 0;});
sort(entire(aft), LAMBI{return ccw(pnts[j], pnts[a], pnts[b]) > 0;});
int ptr = 0, maxd = 0, pid = 0;
for(int k: aft){
while(ptr<bef.size() && ccw(pnts[j], pnts[k], pnts[bef[ptr]]) > 0){
int i = bef[ptr++];
if(maxd <= dp[0][i][j]) maxd = dp[0][i][j]+1, pid = i;
}
dp[1][j][k] = maxd, prv[1][j][k] = pid;
}
reverse(entire(bef)), reverse(entire(aft));
ptr = maxd = pid = 0;
for(int k: aft){
while(ptr<bef.size() && ccw(pnts[j], pnts[k], pnts[bef[ptr]]) < 0){
int i = bef[ptr++];
if(maxd <= dp[1][i][j]) maxd = dp[1][i][j]+1, pid = i;
}
dp[0][j][k] = maxd, prv[0][j][k] = pid;
}
}
// answer
int ans = 0, ai = 0, aj = 0;
for(int i=1; i<n; i++) for(int j=i+1; j<n; j++){
if(ccw(pnts[i], pnts[j], pnts[0]) <= 0) continue;
if(ans < dp[0][i][j]) ans = dp[0][i][j], ai = i, aj = j;
}
if(ans == 0){cout << 0; return 0;}
vector<int> trace = {aj, ai};
while(trace.back()){
int sz = trace.size();
trace.push_back(prv[sz%2][trace[sz-1]][trace[sz-2]]);
}
reverse(entire(trace));
cout<<trace.size()<<'\n';
for(int x: trace) cout<<pnts[x]<<'\n';
}
Compilation message
footprint.cpp: In function 'int main()':
footprint.cpp:47:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ptr<bef.size() && ccw(pnts[j], pnts[k], pnts[bef[ptr]]) > 0){
~~~^~~~~~~~~~~
footprint.cpp:56:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ptr<bef.size() && ccw(pnts[j], pnts[k], pnts[bef[ptr]]) < 0){
~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1027 ms |
98444 KB |
Output is correct |
2 |
Correct |
1063 ms |
100876 KB |
Output is correct |
3 |
Correct |
1035 ms |
99520 KB |
Output is correct |
4 |
Correct |
1054 ms |
100940 KB |
Output is correct |
5 |
Correct |
1065 ms |
100072 KB |
Output is correct |
6 |
Correct |
1064 ms |
101112 KB |
Output is correct |
7 |
Correct |
1047 ms |
100536 KB |
Output is correct |
8 |
Correct |
1056 ms |
101112 KB |
Output is correct |
9 |
Correct |
1079 ms |
101368 KB |
Output is correct |
10 |
Correct |
1063 ms |
101388 KB |
Output is correct |
11 |
Correct |
1073 ms |
101148 KB |
Output is correct |
12 |
Correct |
1070 ms |
101688 KB |
Output is correct |
13 |
Correct |
1096 ms |
103104 KB |
Output is correct |
14 |
Correct |
1069 ms |
101240 KB |
Output is correct |
15 |
Correct |
1091 ms |
99680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
552 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
508 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
380 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
552 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
508 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
380 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
13 ms |
5368 KB |
Output is correct |
22 |
Correct |
14 ms |
5484 KB |
Output is correct |
23 |
Correct |
13 ms |
5368 KB |
Output is correct |
24 |
Correct |
15 ms |
5880 KB |
Output is correct |
25 |
Correct |
15 ms |
5880 KB |
Output is correct |
26 |
Correct |
15 ms |
5880 KB |
Output is correct |
27 |
Correct |
14 ms |
5752 KB |
Output is correct |
28 |
Correct |
15 ms |
5752 KB |
Output is correct |
29 |
Correct |
15 ms |
5752 KB |
Output is correct |
30 |
Correct |
15 ms |
5880 KB |
Output is correct |
31 |
Correct |
16 ms |
5880 KB |
Output is correct |
32 |
Correct |
15 ms |
5884 KB |
Output is correct |
33 |
Correct |
11 ms |
5880 KB |
Output is correct |
34 |
Correct |
10 ms |
5880 KB |
Output is correct |
35 |
Correct |
10 ms |
5880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1027 ms |
98444 KB |
Output is correct |
2 |
Correct |
1063 ms |
100876 KB |
Output is correct |
3 |
Correct |
1035 ms |
99520 KB |
Output is correct |
4 |
Correct |
1054 ms |
100940 KB |
Output is correct |
5 |
Correct |
1065 ms |
100072 KB |
Output is correct |
6 |
Correct |
1064 ms |
101112 KB |
Output is correct |
7 |
Correct |
1047 ms |
100536 KB |
Output is correct |
8 |
Correct |
1056 ms |
101112 KB |
Output is correct |
9 |
Correct |
1079 ms |
101368 KB |
Output is correct |
10 |
Correct |
1063 ms |
101388 KB |
Output is correct |
11 |
Correct |
1073 ms |
101148 KB |
Output is correct |
12 |
Correct |
1070 ms |
101688 KB |
Output is correct |
13 |
Correct |
1096 ms |
103104 KB |
Output is correct |
14 |
Correct |
1069 ms |
101240 KB |
Output is correct |
15 |
Correct |
1091 ms |
99680 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
552 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
504 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
632 KB |
Output is correct |
30 |
Correct |
2 ms |
508 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
380 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
13 ms |
5368 KB |
Output is correct |
37 |
Correct |
14 ms |
5484 KB |
Output is correct |
38 |
Correct |
13 ms |
5368 KB |
Output is correct |
39 |
Correct |
15 ms |
5880 KB |
Output is correct |
40 |
Correct |
15 ms |
5880 KB |
Output is correct |
41 |
Correct |
15 ms |
5880 KB |
Output is correct |
42 |
Correct |
14 ms |
5752 KB |
Output is correct |
43 |
Correct |
15 ms |
5752 KB |
Output is correct |
44 |
Correct |
15 ms |
5752 KB |
Output is correct |
45 |
Correct |
15 ms |
5880 KB |
Output is correct |
46 |
Correct |
16 ms |
5880 KB |
Output is correct |
47 |
Correct |
15 ms |
5884 KB |
Output is correct |
48 |
Correct |
11 ms |
5880 KB |
Output is correct |
49 |
Correct |
10 ms |
5880 KB |
Output is correct |
50 |
Correct |
10 ms |
5880 KB |
Output is correct |
51 |
Correct |
1057 ms |
100884 KB |
Output is correct |
52 |
Correct |
1067 ms |
101216 KB |
Output is correct |
53 |
Correct |
1099 ms |
102776 KB |
Output is correct |
54 |
Correct |
1254 ms |
110984 KB |
Output is correct |
55 |
Correct |
1244 ms |
110912 KB |
Output is correct |
56 |
Correct |
1255 ms |
111056 KB |
Output is correct |
57 |
Correct |
1245 ms |
110616 KB |
Output is correct |
58 |
Correct |
1256 ms |
110820 KB |
Output is correct |
59 |
Correct |
1245 ms |
110708 KB |
Output is correct |
60 |
Correct |
1273 ms |
111004 KB |
Output is correct |
61 |
Correct |
1244 ms |
111096 KB |
Output is correct |
62 |
Correct |
1243 ms |
110956 KB |
Output is correct |
63 |
Correct |
574 ms |
110968 KB |
Output is correct |
64 |
Correct |
571 ms |
110968 KB |
Output is correct |
65 |
Correct |
568 ms |
110840 KB |
Output is correct |
66 |
Correct |
865 ms |
110852 KB |
Output is correct |
67 |
Correct |
855 ms |
110668 KB |
Output is correct |
68 |
Correct |
906 ms |
110716 KB |
Output is correct |