#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
const int N=1e5+500;
const int inf=1e9;
vector<int>E[N];
struct Point{
int x,y;
Point(){}
Point(int u,int v){
x=u,y=v;
}
};
Point operator + (Point A,Point B) {return Point(A.x+B.x,A.y+B.y);}
Point operator - (Point A,Point B) {return Point(A.x-B.x,A.y-B.y);}
int Cross(Point A,Point B) {return A.x*B.y-A.y*B.x;}
bool CW(Point A,Point B,Point C) {return Cross(A-B,C-B)>=0;}
bool CCW(Point A,Point B,Point C) {return !CW(A,B,C);}
bool operator < (Point A,Point B) {return CW(A,Point(0,0),B);}
vector<Point> ConvexHull(vector<Point> a)
{
int n=a.size();
int ind=0;
for(int i=1;i<n;i++) if(a[i].y<a[ind].y || (a[i].y==a[ind].y && a[i].x<a[ind].x)) ind=i;
Point X=a[ind];
swap(a[0],a[ind]);
for(int i=0;i<n;i++) a[i]=a[i]-X;
sort(a.begin()+1,a.end());
vector<Point>chull;
for(int i=0;i<n;i++)
{
while(chull.size()>=2 && CW(chull[chull.size()-2],chull.back(),a[i])) chull.pop_back();
chull.pb(a[i]);
}
for(auto &i:chull) i=i+X;
return chull;
}
bool InPolygon(vector<Point> a,Point X){
bool bul1=false,bul2=false;
for(int i=0;i<a.size();i++){
int j=i+1;if(j==a.size()) j=0;
if(CW(X,a[i],a[j])) bul1=true;
else bul2=true;
}
if(bul1 && bul2) return false;
else return true;
}
int main()
{
int n,m;scanf("%i%i",&n,&m);
Point a[n+1],b[m+1];
vector<Point>temp;
for(int i=1;i<=n;i++) {scanf("%i %i",&a[i].x,&a[i].y);temp.pb(a[i]);}
for(int i=1;i<=m;i++) scanf("%i %i",&b[i].x,&b[i].y);
vector<Point>chull=ConvexHull(temp);
vector<Point>tacke;
for(int i=1;i<=m;i++) if(InPolygon(chull,b[i])) tacke.pb(b[i]);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i==j) continue;
bool bul=true;
for(auto k:tacke) if(!CW(k,a[i],a[j])) bul=false;
if(bul) E[j].pb(i);
}
}
int res=inf;
for(int i=1;i<=n;i++)
{
queue<pair<int,int> >q;
q.push({i,0});
int x=inf;
map<pair<int,int>,bool>was;
bool broke=false;
while(!broke && q.size())
{
int u=q.front().fi,dist=q.front().se;
q.pop();
for(auto j:E[u])
{
if(j==i){x=dist+1;broke=true;break;}
if(!was[{j,dist+1}])
{
was[{j,dist+1}];
q.push({j,dist+1});
}
}
if(broke) break;
}
res=min(res,x);
//cout<<x<<endl;
}
res=111*(m-tacke.size())+20*res;
res=min(res,111*m);
printf("%i\n",res);
//for(auto i:chull) cout<<i.x<<" "<<i.y<<endl;
//cout<<endl;
return 0;
}
Compilation message
fence.cpp: In function 'bool InPolygon(std::vector<Point>, Point)':
fence.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i=0;i<a.size();i++){
| ~^~~~~~~~~
fence.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | int j=i+1;if(j==a.size()) j=0;
| ~^~~~~~~~~~
fence.cpp: In function 'int main()':
fence.cpp:52:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | int n,m;scanf("%i%i",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
fence.cpp:55:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | for(int i=1;i<=n;i++) {scanf("%i %i",&a[i].x,&a[i].y);temp.pb(a[i]);}
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fence.cpp:56:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | for(int i=1;i<=m;i++) scanf("%i %i",&b[i].x,&b[i].y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
825 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
538 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
599 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
466 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
655 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |