Submission #535614

# Submission time Handle Problem Language Result Execution time Memory
535614 2022-03-10T16:40:50 Z new_acc Park (BOI16_park) C++14
100 / 100
1773 ms 33228 KB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=2e3+10;
int mini[5][5],fau[N],n,m,w,h,c[N];
pair<int,int> z[N];
ll odl[N][N];
int Find(int a){
	if(fau[a]==a) return a;
	return fau[a]=Find(fau[a]);
}
void Union(int a,int b){
	fau[Find(a)]=Find(fau[b]);
}
bool check(int x,int a,int b){
	for(int i=1;i<=n+4;i++) fau[i]=i;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j) continue;
			if(odl[i][j]<(ll)(x*2+c[i]+c[j])*(ll)(x*2+c[i]+c[j])) Union(i,j);
		}
	}
	for(int i=1;i<=n;i++){
		if(z[i].se-c[i]<x*2) Union(i,n+1);
		if(w-z[i].fi-c[i]<x*2) Union(i,n+2);
		if(h-z[i].se-c[i]<x*2) Union(i,n+3);
		if(z[i].fi-c[i]<x*2) Union(i,n+4);
	}

	if(a==1 and b==2) return (Find(n+1)!=Find(n+2) and Find(n+1)!=Find(n+4) and Find(n+1)!=Find(n+3));
	if(a==1 and b==3) return (Find(n+2)!=Find(n+3) and Find(n+1)!=Find(n+4) and Find(n+1)!=Find(n+3) and Find(n+2)!=Find(n+4));
	if(a==1 and b==4) return (Find(n+3)!=Find(n+4) and Find(n+1)!=Find(n+4) and Find(n+2)!=Find(n+4));

	if(a==2 and b==3) return (Find(n+1)!=Find(n+2) and Find(n+2)!=Find(n+3) and Find(n+2)!=Find(n+4));
	if(a==2 and b==4) return (Find(n+1)!=Find(n+2) and Find(n+3)!=Find(n+4) and Find(n+1)!=Find(n+3) and Find(n+2)!=Find(n+4));
	//a=3 b=4
	return (Find(n+2)!=Find(n+3) and Find(n+3)!=Find(n+4) and Find(n+1)!=Find(n+3));
}
int bs(int x,int y){
	int res=0,pocz=1,kon=250*1000*1000;
	while(pocz<=kon){
		int sr=(pocz+kon)>>1;
		if(check(sr,x,y)) res=sr,pocz=sr+1;
		else kon=sr-1;
	}
	return res;
}
void solve(){
	cin>>n>>m>>w>>h;
	for(int i=1;i<=n;i++) cin>>z[i].fi>>z[i].se>>c[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			odl[i][j]=(ll)(z[i].fi-z[j].fi)*(ll)(z[i].fi-z[j].fi)+(ll)(z[i].se-z[j].se)*(ll)(z[i].se-z[j].se);
	}
	for(int i=1;i<=4;i++){
		for(int j=1;j<=4;j++){
			if(i==j) {mini[i][j]=1e9;continue;}
			if(i>j) mini[i][j]=mini[j][i];
			else mini[i][j]=bs(i,j);
		}
	}
	while(m--){
		int a,b;
		cin>>a>>b;
		if(mini[b][1]>=a) cout<<"1";
		if(mini[b][2]>=a) cout<<"2";
		if(mini[b][3]>=a) cout<<"3";
		if(mini[b][4]>=a) cout<<"4";
		cout<<"\n";
	}
}
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 779 ms 31804 KB Output is correct
2 Correct 781 ms 31828 KB Output is correct
3 Correct 813 ms 31828 KB Output is correct
4 Correct 800 ms 31812 KB Output is correct
5 Correct 801 ms 31808 KB Output is correct
6 Correct 799 ms 31812 KB Output is correct
7 Correct 1773 ms 31828 KB Output is correct
8 Correct 1749 ms 31820 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 1708 KB Output is correct
2 Correct 43 ms 1700 KB Output is correct
3 Correct 36 ms 1740 KB Output is correct
4 Correct 33 ms 2788 KB Output is correct
5 Correct 34 ms 2764 KB Output is correct
6 Correct 45 ms 2904 KB Output is correct
7 Correct 32 ms 1824 KB Output is correct
8 Correct 25 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 779 ms 31804 KB Output is correct
2 Correct 781 ms 31828 KB Output is correct
3 Correct 813 ms 31828 KB Output is correct
4 Correct 800 ms 31812 KB Output is correct
5 Correct 801 ms 31808 KB Output is correct
6 Correct 799 ms 31812 KB Output is correct
7 Correct 1773 ms 31828 KB Output is correct
8 Correct 1749 ms 31820 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 40 ms 1708 KB Output is correct
12 Correct 43 ms 1700 KB Output is correct
13 Correct 36 ms 1740 KB Output is correct
14 Correct 33 ms 2788 KB Output is correct
15 Correct 34 ms 2764 KB Output is correct
16 Correct 45 ms 2904 KB Output is correct
17 Correct 32 ms 1824 KB Output is correct
18 Correct 25 ms 1740 KB Output is correct
19 Correct 813 ms 33208 KB Output is correct
20 Correct 832 ms 33080 KB Output is correct
21 Correct 805 ms 33228 KB Output is correct
22 Correct 868 ms 33080 KB Output is correct
23 Correct 779 ms 33076 KB Output is correct
24 Correct 1725 ms 33216 KB Output is correct