답안 #299033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
299033 2020-09-14T12:33:10 Z TadijaSebez Fence (CEOI08_fence) C++11
40 / 100
1 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];
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;
	}
	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;
		}
	}
	for(int i=0;i<hull.size();i++)
		for(int j=0;j<hull.size();j++)
			for(int k=0;k<hull.size();k++)
				dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
	int mn=1e9;
	for(int i=0;i<hull.size();i++)mn=min(mn,dist[i][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:45: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]
   45 |  for(int i=0;i<hull.size();i++)
      |              ~^~~~~~~~~~~~
fence.cpp:46: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]
   46 |   for(int j=0;j<hull.size();j++)
      |               ~^~~~~~~~~~~~
fence.cpp:48: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]
   48 |  for(int i=0;i<hull.size();i++){
      |              ~^~~~~~~~~~~~
fence.cpp:49: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]
   49 |   for(int j=0;j<hull.size();j++)if(j!=i){
      |               ~^~~~~~~~~~~~
fence.cpp:55: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]
   55 |  for(int i=0;i<hull.size();i++)
      |              ~^~~~~~~~~~~~
fence.cpp:56: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]
   56 |   for(int j=0;j<hull.size();j++)
      |               ~^~~~~~~~~~~~
fence.cpp:57: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]
   57 |    for(int k=0;k<hull.size();k++)
      |                ~^~~~~~~~~~~~
fence.cpp:60: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]
   60 |  for(int i=0;i<hull.size();i++)mn=min(mn,dist[i][i]);
      |              ~^~~~~~~~~~~~
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 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 288 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't 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 256 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct