Submission #892102

#TimeUsernameProblemLanguageResultExecution timeMemory
892102StefanSebezFence (CEOI08_fence)C++14
100 / 100
2 ms2804 KiB
#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; bool was[n+1]={false}; 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]) { was[j]=true; q.push({j,dist+1}); } } } 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 (stderr)

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);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...