Submission #287841

#TimeUsernameProblemLanguageResultExecution timeMemory
287841nandonathanielPark (BOI16_park)C++14
100 / 100
701 ms66620 KiB
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> pii; const int MAXN=2010; int w,h,par[MAXN]; long double minD[5][5],batas[5][5]; struct tree{ int x,y,r; }; tree a[MAXN]; int find(int x){ if(par[x]==x)return par[x]; return par[x]=find(par[x]); } bool sameSet(int a,int b){ return find(a)==find(b); } void join(int a,int b){ int ortua=find(a),ortub=find(b); par[ortua]=ortub; } long double jarak(int a,int b,int c,int d){ return sqrt((long double)(c-a)*(long double)(c-a)+(long double)(d-b)*(long double)(d-b)); } long double distCircle(int p,int q){ return jarak(a[p].x,a[p].y,a[q].x,a[q].y)-(long double)a[p].r-(long double)a[q].r; } long double distBorder(int p,int q){ //1 bawah,2 kanan,3 atas,4 kiri if(q==1){ return (long double)a[p].y-(long double)a[p].r; } else if(q==2){ return (long double)w-(long double)a[p].x-(long double)a[p].r; } else if(q==3){ return (long double)h-(long double)a[p].y-(long double)a[p].r; } else return (long double)a[p].x-(long double)a[p].r; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int n,m,r,no; cin >> n >> m >> w >> h; for(int i=1;i<=n;i++){ cin >> a[i].x >> a[i].y >> a[i].r; par[i]=i; } vector<pair<long double,pii> > edge; par[n+1]=n+1;par[n+2]=n+2;par[n+3]=n+3;par[n+4]=n+4; for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ edge.push_back({distCircle(i,j),{i,j}}); } for(int j=n+1;j<=n+4;j++){ edge.push_back({distBorder(i,j-n),{i,j}}); } } for(int i=1;i<=4;i++){ for(int j=1;j<=4;j++)minD[i][j]=-1.0; } sort(edge.begin(),edge.end()); for(auto isi : edge){ join(isi.second.first,isi.second.second); for(int i=1;i<=4;i++){ for(int j=i+1;j<=4;j++){ if(sameSet(n+i,n+j) && minD[i][j]==-1.0)minD[i][j]=isi.first; } } } batas[1][1]=batas[2][2]=batas[3][3]=batas[4][4]=2000000005.0; batas[1][2]=batas[2][1]=min(minD[1][2],min(minD[1][3],minD[1][4])); batas[1][3]=batas[3][1]=min(min(minD[1][4],minD[2][3]),min(minD[1][3],minD[2][4])); batas[1][4]=batas[4][1]=min(minD[1][4],min(minD[2][4],minD[3][4])); batas[2][3]=batas[3][2]=min(minD[1][2],min(minD[2][3],minD[2][4])); batas[2][4]=batas[4][2]=min(min(minD[1][2],minD[3][4]),min(minD[1][3],minD[2][4])); batas[3][4]=batas[4][3]=min(minD[3][4],min(minD[1][3],minD[2][3])); while(m--){ cin >> r >> no; r*=2; for(int i=1;i<=4;i++){ if(r<=batas[no][i])cout << i; } cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...