답안 #925646

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925646 2024-02-12T06:49:52 Z pcc Park (BOI16_park) C++17
100 / 100
726 ms 51960 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


const int mxn = 2024;

inline ll sq(ll k){return k*k;}

struct C{
	ll x,y,r;
	C(){}
	C(ll xx,ll yy,ll rr):x(xx),y(yy),r(rr){}
};

struct DSU{
	int dsu[mxn],sz[mxn];
	DSU(){
		for(int i = 0;i<mxn;i++)dsu[i] = i,sz[i] = 1;
	}
	void init(){
		for(int i = 0;i<mxn;i++)dsu[i] = i,sz[i] = 1;
	}
	int root(int k){
		return k == dsu[k]?k:dsu[k] = root(dsu[k]);
	}
	void onion(int a,int b){
		a = root(a),b = root(b);
		if(a == b)return;
		if(sz[a]<sz[b])swap(a,b);
		sz[a] += sz[b];
		dsu[b] = a;
		return;
	}
};

int N,Q;
ll H,W;
C arr[mxn];
vector<pair<ll,pll>> v;
ll neck[5][5];
vector<pii> req[5][5];
bool done[5][5];
DSU dsu;

inline void getr(int a,int b,ll R){
	ll l = 0,r = min(H,W);
	while(l != r){
		ll mid = (l+r+1)>>1;
		if(sq(mid+arr[a].r+arr[b].r)<=R)l = mid;
		else r = mid-1;
	}
	//cout<<a<<' '<<b<<":"<<R<<' '<<l<<endl;
	v.push_back(make_pair(l,make_pair(a,b)));
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>Q>>W>>H;
	for(int i = 1;i<=N;i++){
		cin>>arr[i].x>>arr[i].y>>arr[i].r;
	}
	for(int i = 1;i<=N;i++){
		for(int j = i+1;j<=N;j++){
			getr(i,j,sq(arr[i].x-arr[j].x)+sq(arr[i].y-arr[j].y));
		}
		getr(i,N+1,sq(arr[i].x));
		getr(i,N+2,sq(H-arr[i].y));
		getr(i,N+3,sq(W-arr[i].x));
		getr(i,N+4,sq(arr[i].y));
	}
	getr(N+1,N+3,sq(W));
	getr(N+2,N+4,sq(H));
	sort(v.begin(),v.end());
	req[1][2] = {{2,4},{3,4},{1,4}};
	req[1][3] = {{2,4},{1,4},{1,3},{2,3}};
	req[1][4] = {{1,3},{1,2},{1,4}};
	req[2][3] = {{1,3},{2,3},{3,4}};
	req[2][4] = {{1,3},{2,4},{1,2},{3,4}};
	req[3][4] = {{2,4},{1,2},{2,3}};
	for(int i = 1;i<=4;i++)neck[i][i] = min(H,W);
	//cout<<endl;
	for(auto &now:v){
		//cout<<now.fs<<' '<<now.sc.fs<<' '<<now.sc.sc<<endl;
		dsu.onion(now.sc.fs,now.sc.sc);
		for(int i = 1;i<=4;i++){
			for(int j = i+1;j<=4;j++){
				bool flag = true;
				for(auto &k:req[i][j]){
					if(dsu.root(N+k.fs) == dsu.root(N+k.sc))flag = false;
				}
				if(!done[i][j])neck[j][i] = neck[i][j] = now.fs;
				if(!flag)done[i][j] = true;
			}
		}
	}
	/*
	for(int i = 1;i<=4;i++){
		for(int j = 1;j<=4;j++)cout<<neck[i][j]<<' ';cout<<endl;
	}

   */
	while(Q--){
		ll n,r;
		cin>>r>>n;
		for(int i = 1;i<=4;i++){
			if(neck[n][i]>=r*2)cout<<i;
		}
		cout<<'\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 716 ms 51104 KB Output is correct
2 Correct 713 ms 50188 KB Output is correct
3 Correct 698 ms 49992 KB Output is correct
4 Correct 699 ms 50216 KB Output is correct
5 Correct 711 ms 50504 KB Output is correct
6 Correct 699 ms 51596 KB Output is correct
7 Correct 640 ms 49984 KB Output is correct
8 Correct 632 ms 50924 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 2284 KB Output is correct
2 Correct 33 ms 2460 KB Output is correct
3 Correct 30 ms 2292 KB Output is correct
4 Correct 33 ms 2456 KB Output is correct
5 Correct 35 ms 2396 KB Output is correct
6 Correct 40 ms 2384 KB Output is correct
7 Correct 26 ms 1884 KB Output is correct
8 Correct 24 ms 1752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 716 ms 51104 KB Output is correct
2 Correct 713 ms 50188 KB Output is correct
3 Correct 698 ms 49992 KB Output is correct
4 Correct 699 ms 50216 KB Output is correct
5 Correct 711 ms 50504 KB Output is correct
6 Correct 699 ms 51596 KB Output is correct
7 Correct 640 ms 49984 KB Output is correct
8 Correct 632 ms 50924 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 35 ms 2284 KB Output is correct
12 Correct 33 ms 2460 KB Output is correct
13 Correct 30 ms 2292 KB Output is correct
14 Correct 33 ms 2456 KB Output is correct
15 Correct 35 ms 2396 KB Output is correct
16 Correct 40 ms 2384 KB Output is correct
17 Correct 26 ms 1884 KB Output is correct
18 Correct 24 ms 1752 KB Output is correct
19 Correct 725 ms 51960 KB Output is correct
20 Correct 677 ms 50244 KB Output is correct
21 Correct 726 ms 50860 KB Output is correct
22 Correct 601 ms 50344 KB Output is correct
23 Correct 722 ms 50600 KB Output is correct
24 Correct 654 ms 50644 KB Output is correct