답안 #299067

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
299067 2020-09-14T12:57:22 Z TadijaSebez Fence (CEOI08_fence) C++11
100 / 100
2 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define pt pair<int,int>
#define x first
#define y second
#define pb push_back
int cross(pt a,pt b){return a.x*b.y-a.y*b.x;}
pt operator - (pt a,pt b){return {a.x-b.x,a.y-b.y};}
const int N=105;
pt a[N],b[N];
vector<pt> CH(pt a[],int n){
	sort(a+1,a+1+n);
	vector<pt> hull;
	for(int t=0,sz=0;t<2;t++){
		int h=sz;
		for(int i=1;i<=n;i++){
			while(sz-h>1&&cross(hull[sz-1]-hull[sz-2],a[i]-hull[sz-2])<0)hull.pop_back(),sz--;
			hull.pb(a[i]);sz++;
		}
		hull.pop_back();sz--;
		reverse(a+1,a+1+n);
	}
	return hull;
}
bool is_inside(vector<pt> hull,pt p){
	for(int i=0;i<hull.size();i++){
		int j=(i+1)%hull.size();
		if(cross(hull[j]-hull[i],p-hull[i])<0)return 0;
	}
	return 1;
}
int dist[N][N],dp[N];
int main(){
	int n,m;
	scanf("%i %i",&n,&m);
	for(int i=1;i<=n;i++)scanf("%i %i",&a[i].x,&a[i].y);
	for(int i=1;i<=m;i++)scanf("%i %i",&b[i].x,&b[i].y);
	vector<pt> hull=CH(a,n),inside;
	int ans=0;
	for(int i=1;i<=m;i++){
		if(is_inside(hull,b[i]))
			inside.pb(b[i]);
		else ans+=111;
	}
	hull.clear();
	for(int i=1;i<=n;i++)hull.pb(a[i]);
	for(int i=0;i<hull.size();i++)
		for(int j=0;j<hull.size();j++)
			dist[i][j]=1e9;
	for(int i=0;i<hull.size();i++){
		for(int j=0;j<hull.size();j++)if(j!=i){
			bool ok=1;
			for(pt p:inside)if(cross(hull[j]-hull[i],p-hull[i])>0)ok=0;
			if(ok)dist[i][j]=1;
		}
	}
	int mn=1e9;
	for(int i=0;i<hull.size();i++){
		queue<int> q;
		for(int j=0;j<hull.size();j++){
			if(dist[i][j]!=1)dp[j]=1e9;
			else dp[j]=1,q.push(j);
		}
		while(q.size()){
			int k=q.front();
			q.pop();
			for(int j=0;j<hull.size();j++)if(dist[k][j]==1){
				if(dp[j]>dp[k]+1){
					dp[j]=dp[k]+1;
					q.push(j);
				}
			}
		}
		mn=min(mn,dp[i]);
	}
	if(inside.size()>0)ans+=20*mn;
	printf("%i\n",ans);
	return 0;
}

Compilation message

fence.cpp: In function 'bool is_inside(std::vector<std::pair<int, int> >, std::pair<int, int>)':
fence.cpp:26:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i=0;i<hull.size();i++){
      |              ~^~~~~~~~~~~~
fence.cpp: In function 'int main()':
fence.cpp:47:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(int i=0;i<hull.size();i++)
      |              ~^~~~~~~~~~~~
fence.cpp:48:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for(int j=0;j<hull.size();j++)
      |               ~^~~~~~~~~~~~
fence.cpp:50:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for(int i=0;i<hull.size();i++){
      |              ~^~~~~~~~~~~~
fence.cpp:51:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int j=0;j<hull.size();j++)if(j!=i){
      |               ~^~~~~~~~~~~~
fence.cpp:58:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(int i=0;i<hull.size();i++){
      |              ~^~~~~~~~~~~~
fence.cpp:60:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for(int j=0;j<hull.size();j++){
      |               ~^~~~~~~~~~~~
fence.cpp:67:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |    for(int j=0;j<hull.size();j++)if(dist[k][j]==1){
      |                ~^~~~~~~~~~~~
fence.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |  scanf("%i %i",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~
fence.cpp:36:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |  for(int i=1;i<=n;i++)scanf("%i %i",&a[i].x,&a[i].y);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fence.cpp:37:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |  for(int i=1;i<=m;i++)scanf("%i %i",&b[i].x,&b[i].y);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct