# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
64574 |
2018-08-04T23:56:06 Z |
kjp4155 |
None (KOI18_footprint) |
C++17 |
|
1438 ms |
160228 KB |
#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});
}
v.push_back({0,0,0});
// 나머지 점들(1,2,...,N-1)을 모두 반시계방향으로 정렬
sort( v.begin(), v.end() , [](Point& a, Point& b){
return ccw(a,b) > 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++) R.push_back(v[j]);
for(int j=i+1;j<v.size();j++) 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:112:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();i++){
~^~~~~~~~~
footprint.cpp:116:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=i+1;j<v.size();j++) L.push_back(v[j]);
~^~~~~~~~~
footprint.cpp:131: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:158: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]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1438 ms |
160228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
160228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
160228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1438 ms |
160228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |