답안 #63152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63152 2018-08-01T01:15:56 Z khsoo01 공룡 발자국 (KOI18_footprint) C++11
0 / 100
1326 ms 70000 KB
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef pair<int,int> pii;

const int N = 3005, inf = 1e9;

int n;
pii a[N], dt[N][N][2], piv;

vector<int> ans;

long long ccw (pii &A, pii &B, pii &C) {
	return (1ll*A.X*B.Y+1ll*B.X*C.Y+1ll*C.X*A.Y) - (1ll*A.Y*B.X+1ll*B.Y*C.X+1ll*C.Y*A.X);
}

bool cmp (pii &A, pii &B) {
	return ccw(piv, A, B) > 0;
}

bool cmp2 (int A, int B) {
	return ccw(piv, a[A], a[B]) > 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d%d",&a[i].X,&a[i].Y);
		if(a[i].Y < a[1].Y) swap(a[i], a[1]);
	}
	piv = a[1];
	sort(a+2, a+1+n, cmp);
	for(int i=1;i<=n;i++) {
		dt[1][i][0] = {1, 0};
	}
	for(int k=2;k<=n;k++) {
		vector<int> A, B;
		A.push_back(1);
		for(int i=2;i<k;i++) {
			if(ccw(a[1], a[k], a[i]) != 0) A.push_back(i);
		}
		for(int i=k+1;i<=n;i++) {
			if(ccw(a[1], a[k], a[i]) != 0) B.push_back(i);
		}
		piv = a[k];
		sort(A.begin(), A.end(), cmp2);
		sort(B.begin(), B.end(), cmp2);
		int j = 0;
		pii V = {-inf, -inf};
		for(int i=0;i<=(int)A.size();i++) {
			int T = (i < (int)A.size() ? A[i] : k);
			while(j<(int)B.size() && ccw(a[T], a[k], a[B[j]]) <= 0) {
				dt[k][B[j]][1] = max(dt[k][B[j]][1], V);
				j++;
			}
			V = max(V, {dt[T][k][0].X+1, T});
		}
		j = (int)B.size()-1;
		V = {-inf, -inf};
		for(int i=(int)A.size()-1;i>=-1;i--) {
			int T = (i >= 0 ? A[i] : k);
			while(j >= 0 && ccw(a[T], a[k], a[B[j]]) >= 0) {
				dt[k][B[j]][0] = max(dt[k][B[j]][0], V);
				j--;
			}
			V = max(V, {dt[T][k][1].X+1, T});
		}
	}
	int V = 0, A, B, C = 0;
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			if(V < dt[i][j][0].X) {
				V = dt[i][j][0].X;
				A = i;
				B = j;
			}
		}
	}
	if(V == 1) {
		puts("0");
		return 0;
	}
	for(int i=0;i<V;i++) {
		ans.push_back(B);
		int T = A;
		A = dt[A][B][C].Y;
		A = B;
		C ^= 1;
	}
	ans.push_back(1);
	reverse(ans.begin(), ans.end());
	printf("%d\n",(int)ans.size());
	for(auto &T : ans) {
		printf("%d %d\n", a[T].X, a[T].Y);
	}
}

Compilation message

footprint.cpp: In function 'int main()':
footprint.cpp:87:7: warning: unused variable 'T' [-Wunused-variable]
   int T = A;
       ^
footprint.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
footprint.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&a[i].X,&a[i].Y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1326 ms 70000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 70000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 70000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1326 ms 70000 KB Output isn't correct
2 Halted 0 ms 0 KB -