Submission #68981

#TimeUsernameProblemLanguageResultExecution timeMemory
68981VahanPark (BOI16_park)C++17
100 / 100
699 ms46544 KiB
#include<iostream> #include<vector> #include<algorithm> #include<cmath> #include<string> using namespace std; int n,m,k[6][6],w,h,p[4000],sz[4000]; long long x[4000],y[4000],r[4000]; pair<pair<int,int>,int> aa[100005]; int pat[100005][5]; vector< pair <double,pair<int,int> > > g; void stug(int a,int b) { if(a==n+1) { if(b==n+2) { k[4][3]=1; k[4][2]=1; k[4][1]=1; } if(b==n+3) { k[4][1]=1; k[4][2]=1; k[3][1]=1; k[3][2]=1; } if(b==n+4) { k[1][4]=1; k[1][3]=1; k[1][2]=1; } } if(a==n+2) { if(b==n+3) { k[3][1]=1; k[3][2]=1; k[3][4]=1; } if(b==n+4) { k[3][1]=1; k[3][4]=1; k[2][1]=1; k[2][4]=1; } } if(a==n+3) { if(b==n+4) { k[2][1]=1; k[2][3]=1; k[2][4]=1; } } } double dis(int a,int b) { return (double)sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]))-r[a]-r[b]; } void create(int a) { sz[a]=0; p[a]=a; } int findparent(int a) { if(a==p[a]) return a; p[a]=findparent(p[a]); return p[a]; } void unionset(int a,int b) { a=findparent(a); b=findparent(b); if(a==b) return; if(sz[a]>=sz[b]) { p[b]=a; sz[a]+=sz[b]; } else { p[a]=b; sz[b]+=sz[a]; } } int main() { cin>>n>>m; cin>>w>>h; for(int i=1;i<=n;i++) cin>>x[i]>>y[i]>>r[i]; for(int i=1;i<n;i++) { for(int j=i+1;j<=n;j++) { double e=dis(i,j); g.push_back(make_pair(e,make_pair(i,j))); } } for(int i=1;i<=n;i++) { g.push_back(make_pair(x[i]-r[i],make_pair(i,n+1))); g.push_back(make_pair(h-y[i]-r[i],make_pair(i,n+2))); g.push_back(make_pair(w-x[i]-r[i],make_pair(i,n+3))); g.push_back(make_pair(y[i]-r[i],make_pair(i,n+4))); } sort(g.begin(),g.end()); for(int i=1;i<=m;i++) { cin>>aa[i].first.first>>aa[i].first.second; aa[i].second=i; aa[i].first.first*=2; } sort(aa+1,aa+m+1); int t=0; for(int i=1;i<=n+4;i++) create(i); for(int i=1;i<=m;i++) { while((double)(aa[i].first.first)>g[t].first) { unionset(g[t].second.first,g[t].second.second); t++; } for(int j=n+1;j<n+4;j++) { for(int e=j+1;e<=n+4;e++) { if(findparent(e)==findparent(j)) stug(j,e); } } for(int j=1;j<=4;j++) { if(k[aa[i].first.second][j]==0 && k[j][aa[i].first.second]==0) pat[aa[i].second][j]=1; } for(int j=1;j<=4;j++) { for(int e=1;e<=4;e++) k[j][e]=0; } } for(int i=1;i<=m;i++) { for(int j=1;j<=4;j++) if(pat[i][j]==1) cout<<j; cout<<endl; } return 0; } /* 5 3 16 11 11 8 1 6 10 1 7 3 2 10 4 1 15 5 1 1 1 2 2 2 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...