#include<bits/stdc++.h>
using namespace std;
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 6,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,_6,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define Debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define Debug2(a,b) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define Debug3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define Debug4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define Debug5(a,b,c,d,e) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define Debug6(a,b,c,d,e,f) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define Debug(...) macro_dispatcher(Debug, __VA_ARGS__)(__VA_ARGS__)
#define DA(a,n) cout<<#a<<"=["; printarray(a,n); cout<<"]\n"
#define DAR(a,n,s) cout<<#a<<"["<<s<<"-"<<n-1<<"]=["; printarray(a,n,s); cout<<"]\n"
#define TT1 template<class T>
#define TT1T2 template<class T1, class T2>
#define TT1T2T3 template<class T1, class T2, class T3>
template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v);
TT1T2 ostream& operator << (ostream& os, const pair<T1, T2>& p){ return os <<"("<<p.first<<", "<< p.second<<")"; }
TT1 ostream& operator << (ostream& os, const vector<T>& v){ bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v) { bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const set<T1, T2>&v){ bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const multiset<T1,T2>&v){bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2T3 ostream& operator << (ostream& os, const map<T1,T2,T3>& v){ bool f = 1; os << "["; for (auto& ii : v) { if (!f)os << ", "; os << "(" << ii.first << " -> " << ii.second << ") "; f = 0; }return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const multimap<T1, T2>& v){ bool f = 1; os << "["; for (auto& ii : v) { if (!f)os << ", "; os << "(" << ii.first << " -> " << ii.second << ") "; f = 0; }return os << "]"; }
TT1T2 ostream& operator << (ostream& os, priority_queue<T1, T2> v) { bool f = 1; os << "["; while (!v.empty()) { auto x = v.top(); v.pop(); if (!f) os << ", "; f = 0; os << x; } return os << "]"; }
TT1T2 void printarray(const T1& a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()
#define geti1(X) cin >> X
#define geti2(X,Y) cin >> X >> Y
#define geti3(X,Y,Z) cin >> X >> Y >> Z
#define geti4(X,Y,Z,W) cin >> X >> Y >> Z >> W
#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)
#define INF 987654321
#define endl '\n'
const ll mod = 1e9 + 7;
const ll inf = 1e14;
/*
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
*/
// 계산을 편리하게 하기 위한 Point구조체 및 몇가지 연산자 정의
struct Point{
ll x,y,n;
};
Point operator - (Point a, Point b){
return {a.x-b.x, a.y-b.y, a.n};
}
ll ccw(Point a, Point b){
return a.x * b.y - a.y * b.x;
}
int N;
ll xbase = 0, ybase = 1e9;
ll X[5050], Y[5050];
vector<Point> v;
int dp1[5050][5050], dp2[5050][5050];
int prev1[5050][5050], prev2[5050][5050];
int main(){
scanf("%d",&N);
for(int i=1;i<=N;i++){
scanf("%lld%lld",&X[i],&Y[i]);
if( ybase > Y[i] ){
ybase = Y[i]; xbase = X[i];
}
}
// 발뒤꿈치를 원점으로 하도록 점들을 평행이동시키자
for(int i=1;i<=N;i++){
X[i] -= xbase; Y[i] -= ybase;
if( X[i] == 0 && Y[i] == 0 ) continue;
v.push_back({X[i], Y[i], i});
}
// 나머지 점들(1,2,...,N-1)을 모두 반시계방향으로 정렬
sort( v.begin(), v.end() , [](Point& a, Point& b){
return ccw(a,b) > 0;
} );
v.push_back({0,0,0});
// i를 고정시키고 슬라이딩 윈도우 기법으로 dp1[i][j], dp2[i][j]를 모두 채우자
for(int i=0;i<v.size();i++){
vector<Point> L,R;
for(int j=0;j<i;j++){
if( ccw(v[j], v[i]) == 0 ) continue;
R.push_back(v[j]);
}
for(int j=i+1;j<v.size();j++){
if( j != v.size()-1 && ccw(v[j], v[i]) == 0 ) continue;
L.push_back(v[j]);
}
// dp1 채우기
sort(L.begin(), L.end(), [i](Point a, Point b){
return ccw(a-v[i], b-v[i]) > 0;
});
sort(R.begin(), R.end(), [i](Point a, Point b){
return ccw(a-v[i], b-v[i]) > 0;
});
int pos = -1;
int mx = 0, mxx = 0;
for(auto p : L){
while( pos+1 < R.size() && ccw( v[i]-p , R[pos+1]-p ) < 0 ){
pos++;
if( mx < dp2[ R[pos].n ][ v[i].n ] ){
mx = dp2[ R[pos].n ][ v[i].n ];
mxx = R[pos].n;
}
}
if( dp1[ v[i].n ][ p.n ] < mx+1 ){
dp1[ v[i].n ][ p.n ] = mx + 1;
prev1[ v[i].n ][ p.n ] =mxx;
// printf("dp1[ %lld ][ %lld ] = %d prev = %d \n", v[i].n, p.n, mx+1, mxx );
}
}
// dp2 채우기
sort(L.begin(), L.end(), [i](Point a, Point b){
return ccw(a-v[i], b-v[i]) < 0;
});
sort(R.begin(), R.end(), [i](Point a, Point b){
return ccw(a-v[i], b-v[i]) < 0;
});
pos = -1; mx = 0, mxx = 0;
for(auto p : L){
if( p.n == 0 ) continue;
while( pos+1 < R.size() && ccw( v[i]-p , R[pos+1]-p ) > 0 ){
pos++;
if( mx < dp1[ R[pos].n ][ v[i].n ] ){
mx = dp1[ R[pos].n ][ v[i].n ];
mxx = R[pos].n;
}
}
// 골은 적어도 두번째 점부터 시작
if( mx >= 1 && dp2[ v[i].n ][ p.n ] < mx+1 ){
// printf("dp2[ %lld ][ %lld ] = %d prev = %d \n", v[i].n, p.n, mx+1, mxx );
dp2[ v[i].n ][ p.n ] = mx + 1;
prev2[ v[i].n ][ p.n ] = mxx;
}
}
}
int mx = -1, mxx = 0;
for(int i=1;i<=N;i++){
if( mx < dp1[i][0] ){
mx = dp1[i][0];
mxx = i;
}
}
// 발자국을 만들수 없는 경우 (발가락이 1개 이하)
if( mx < 3 ){
printf("0\n");
return 0;
}
vector<pair<ll,ll>> ansv;
int cur = mxx, nxt = 0;
while( true ){
//printf("%d %d\n",cur,nxt);
ansv.push_back({X[cur]+xbase, Y[cur]+ybase});
if( dp1[cur][nxt] == 1 ) break;
int pre = prev1[cur][nxt];
nxt = cur;
cur = pre;
//printf("%d %d\n",cur,nxt);
ansv.push_back({X[cur]+xbase, Y[cur]+ybase});
pre = prev2[cur][nxt];
nxt = cur;
cur = pre;
}
ansv.push_back({xbase, ybase});
printf("%d\n", mx+1);
reverse( ansv.begin(), ansv.end() );
for(auto e : ansv) printf("%lld %lld\n",e.first, e.second);
}
Compilation message
footprint.cpp: In function 'int main()':
footprint.cpp:114:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();i++){
~^~~~~~~~~
footprint.cpp:121:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=i+1;j<v.size();j++){
~^~~~~~~~~
footprint.cpp:122:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if( j != v.size()-1 && ccw(v[j], v[i]) == 0 ) continue;
~~^~~~~~~~~~~~~
footprint.cpp:137:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while( pos+1 < R.size() && ccw( v[i]-p , R[pos+1]-p ) < 0 ){
~~~~~~^~~~~~~~~~
footprint.cpp:164:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while( pos+1 < R.size() && ccw( v[i]-p , R[pos+1]-p ) > 0 ){
~~~~~~^~~~~~~~~~
footprint.cpp:91:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&N);
~~~~~^~~~~~~~~
footprint.cpp:93:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&X[i],&Y[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1550 ms |
160436 KB |
Output is correct |
2 |
Correct |
1783 ms |
165708 KB |
Output is correct |
3 |
Correct |
1535 ms |
165708 KB |
Output is correct |
4 |
Correct |
1596 ms |
166020 KB |
Output is correct |
5 |
Correct |
1619 ms |
166020 KB |
Output is correct |
6 |
Correct |
1667 ms |
166088 KB |
Output is correct |
7 |
Correct |
1639 ms |
166088 KB |
Output is correct |
8 |
Correct |
1513 ms |
166688 KB |
Output is correct |
9 |
Correct |
1384 ms |
167196 KB |
Output is correct |
10 |
Correct |
1716 ms |
167196 KB |
Output is correct |
11 |
Correct |
1627 ms |
167196 KB |
Output is correct |
12 |
Correct |
1632 ms |
167392 KB |
Output is correct |
13 |
Correct |
1646 ms |
171340 KB |
Output is correct |
14 |
Correct |
1643 ms |
171340 KB |
Output is correct |
15 |
Correct |
1459 ms |
171340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
171340 KB |
Output is correct |
2 |
Correct |
4 ms |
171340 KB |
Output is correct |
3 |
Correct |
3 ms |
171340 KB |
Output is correct |
4 |
Correct |
3 ms |
171340 KB |
Output is correct |
5 |
Correct |
3 ms |
171340 KB |
Output is correct |
6 |
Correct |
3 ms |
171340 KB |
Output is correct |
7 |
Correct |
3 ms |
171340 KB |
Output is correct |
8 |
Correct |
5 ms |
171340 KB |
Output is correct |
9 |
Correct |
3 ms |
171340 KB |
Output is correct |
10 |
Correct |
2 ms |
171340 KB |
Output is correct |
11 |
Correct |
3 ms |
171340 KB |
Output is correct |
12 |
Correct |
3 ms |
171340 KB |
Output is correct |
13 |
Correct |
2 ms |
171340 KB |
Output is correct |
14 |
Correct |
4 ms |
171340 KB |
Output is correct |
15 |
Correct |
3 ms |
171340 KB |
Output is correct |
16 |
Correct |
3 ms |
171340 KB |
Output is correct |
17 |
Correct |
2 ms |
171340 KB |
Output is correct |
18 |
Correct |
2 ms |
171340 KB |
Output is correct |
19 |
Correct |
2 ms |
171340 KB |
Output is correct |
20 |
Correct |
3 ms |
171340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
171340 KB |
Output is correct |
2 |
Correct |
4 ms |
171340 KB |
Output is correct |
3 |
Correct |
3 ms |
171340 KB |
Output is correct |
4 |
Correct |
3 ms |
171340 KB |
Output is correct |
5 |
Correct |
3 ms |
171340 KB |
Output is correct |
6 |
Correct |
3 ms |
171340 KB |
Output is correct |
7 |
Correct |
3 ms |
171340 KB |
Output is correct |
8 |
Correct |
5 ms |
171340 KB |
Output is correct |
9 |
Correct |
3 ms |
171340 KB |
Output is correct |
10 |
Correct |
2 ms |
171340 KB |
Output is correct |
11 |
Correct |
3 ms |
171340 KB |
Output is correct |
12 |
Correct |
3 ms |
171340 KB |
Output is correct |
13 |
Correct |
2 ms |
171340 KB |
Output is correct |
14 |
Correct |
4 ms |
171340 KB |
Output is correct |
15 |
Correct |
3 ms |
171340 KB |
Output is correct |
16 |
Correct |
3 ms |
171340 KB |
Output is correct |
17 |
Correct |
2 ms |
171340 KB |
Output is correct |
18 |
Correct |
2 ms |
171340 KB |
Output is correct |
19 |
Correct |
2 ms |
171340 KB |
Output is correct |
20 |
Correct |
3 ms |
171340 KB |
Output is correct |
21 |
Correct |
21 ms |
171340 KB |
Output is correct |
22 |
Correct |
21 ms |
171340 KB |
Output is correct |
23 |
Correct |
15 ms |
171340 KB |
Output is correct |
24 |
Correct |
16 ms |
171340 KB |
Output is correct |
25 |
Correct |
17 ms |
171340 KB |
Output is correct |
26 |
Correct |
18 ms |
171340 KB |
Output is correct |
27 |
Correct |
21 ms |
171340 KB |
Output is correct |
28 |
Correct |
23 ms |
171340 KB |
Output is correct |
29 |
Correct |
20 ms |
171340 KB |
Output is correct |
30 |
Correct |
26 ms |
171340 KB |
Output is correct |
31 |
Correct |
21 ms |
171340 KB |
Output is correct |
32 |
Correct |
22 ms |
171340 KB |
Output is correct |
33 |
Correct |
12 ms |
171340 KB |
Output is correct |
34 |
Correct |
16 ms |
171340 KB |
Output is correct |
35 |
Correct |
13 ms |
171340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1550 ms |
160436 KB |
Output is correct |
2 |
Correct |
1783 ms |
165708 KB |
Output is correct |
3 |
Correct |
1535 ms |
165708 KB |
Output is correct |
4 |
Correct |
1596 ms |
166020 KB |
Output is correct |
5 |
Correct |
1619 ms |
166020 KB |
Output is correct |
6 |
Correct |
1667 ms |
166088 KB |
Output is correct |
7 |
Correct |
1639 ms |
166088 KB |
Output is correct |
8 |
Correct |
1513 ms |
166688 KB |
Output is correct |
9 |
Correct |
1384 ms |
167196 KB |
Output is correct |
10 |
Correct |
1716 ms |
167196 KB |
Output is correct |
11 |
Correct |
1627 ms |
167196 KB |
Output is correct |
12 |
Correct |
1632 ms |
167392 KB |
Output is correct |
13 |
Correct |
1646 ms |
171340 KB |
Output is correct |
14 |
Correct |
1643 ms |
171340 KB |
Output is correct |
15 |
Correct |
1459 ms |
171340 KB |
Output is correct |
16 |
Correct |
3 ms |
171340 KB |
Output is correct |
17 |
Correct |
4 ms |
171340 KB |
Output is correct |
18 |
Correct |
3 ms |
171340 KB |
Output is correct |
19 |
Correct |
3 ms |
171340 KB |
Output is correct |
20 |
Correct |
3 ms |
171340 KB |
Output is correct |
21 |
Correct |
3 ms |
171340 KB |
Output is correct |
22 |
Correct |
3 ms |
171340 KB |
Output is correct |
23 |
Correct |
5 ms |
171340 KB |
Output is correct |
24 |
Correct |
3 ms |
171340 KB |
Output is correct |
25 |
Correct |
2 ms |
171340 KB |
Output is correct |
26 |
Correct |
3 ms |
171340 KB |
Output is correct |
27 |
Correct |
3 ms |
171340 KB |
Output is correct |
28 |
Correct |
2 ms |
171340 KB |
Output is correct |
29 |
Correct |
4 ms |
171340 KB |
Output is correct |
30 |
Correct |
3 ms |
171340 KB |
Output is correct |
31 |
Correct |
3 ms |
171340 KB |
Output is correct |
32 |
Correct |
2 ms |
171340 KB |
Output is correct |
33 |
Correct |
2 ms |
171340 KB |
Output is correct |
34 |
Correct |
2 ms |
171340 KB |
Output is correct |
35 |
Correct |
3 ms |
171340 KB |
Output is correct |
36 |
Correct |
21 ms |
171340 KB |
Output is correct |
37 |
Correct |
21 ms |
171340 KB |
Output is correct |
38 |
Correct |
15 ms |
171340 KB |
Output is correct |
39 |
Correct |
16 ms |
171340 KB |
Output is correct |
40 |
Correct |
17 ms |
171340 KB |
Output is correct |
41 |
Correct |
18 ms |
171340 KB |
Output is correct |
42 |
Correct |
21 ms |
171340 KB |
Output is correct |
43 |
Correct |
23 ms |
171340 KB |
Output is correct |
44 |
Correct |
20 ms |
171340 KB |
Output is correct |
45 |
Correct |
26 ms |
171340 KB |
Output is correct |
46 |
Correct |
21 ms |
171340 KB |
Output is correct |
47 |
Correct |
22 ms |
171340 KB |
Output is correct |
48 |
Correct |
12 ms |
171340 KB |
Output is correct |
49 |
Correct |
16 ms |
171340 KB |
Output is correct |
50 |
Correct |
13 ms |
171340 KB |
Output is correct |
51 |
Correct |
1789 ms |
171340 KB |
Output is correct |
52 |
Correct |
1750 ms |
171340 KB |
Output is correct |
53 |
Correct |
1443 ms |
171340 KB |
Output is correct |
54 |
Correct |
1909 ms |
189776 KB |
Output is correct |
55 |
Correct |
1739 ms |
189776 KB |
Output is correct |
56 |
Correct |
1698 ms |
190016 KB |
Output is correct |
57 |
Correct |
1814 ms |
190016 KB |
Output is correct |
58 |
Correct |
1755 ms |
190016 KB |
Output is correct |
59 |
Correct |
1712 ms |
190016 KB |
Output is correct |
60 |
Correct |
1910 ms |
190016 KB |
Output is correct |
61 |
Correct |
1884 ms |
190016 KB |
Output is correct |
62 |
Correct |
1976 ms |
190016 KB |
Output is correct |
63 |
Correct |
707 ms |
190016 KB |
Output is correct |
64 |
Correct |
753 ms |
190016 KB |
Output is correct |
65 |
Correct |
715 ms |
190016 KB |
Output is correct |
66 |
Correct |
1413 ms |
190540 KB |
Output is correct |
67 |
Correct |
1526 ms |
190844 KB |
Output is correct |
68 |
Correct |
1734 ms |
190892 KB |
Output is correct |