Submission #1299359

#TimeUsernameProblemLanguageResultExecution timeMemory
1299359Jawad_Akbar_JJPark (BOI16_park)C++20
0 / 100
2597 ms80064 KiB
#include <iostream>
#include <queue>

using namespace std;
const int N = 2005;
vector<int> nei[N * N];
int seen[4][N * N], x[N], y[N], r[N], cur = 1;
int n, m, w, h;

void bfs(int s, int id){
	queue<int> Q; Q.push(s);
	seen[id][s] = 1;

	while (Q.size() > 0){
		s = Q.front();
		Q.pop();

		for (int i : nei[s]){
			if (seen[id][i] != 1)
				seen[id][i] = 1, Q.push(i);
		}
	}
}

int sq(int k){
	return k * k;
}

bool none(int a, int b, int c, int d, int e, int f, int g, int h){
	return (seen[a-1][b] + seen[c-1][d] + seen[e-1][f] + seen[g-1][h]) == 0;
}

string get(int rd, int num = 0){
	for (int i=5;i<=n;i++){
		if (x[i] <= r[i] + rd){
			nei[2].push_back(i);
			nei[i].push_back(2);
		}
		if (w - x[i] <= r[i] + rd){
			nei[3].push_back(i);
			nei[i].push_back(3);
		}
		if (y[i] <= r[i] + rd){
			nei[4].push_back(i);
			nei[i].push_back(4);
		}
		if (h - y[i] <= r[i] + rd){
			nei[1].push_back(i);
			nei[i].push_back(1);
		}
		
		for (int j=5;j<=n;j++){
			if (i != j and sq(rd + rd + r[i] + r[j]) > sq(x[i] - x[j]) + sq(y[i] - y[j]))
				nei[i].push_back(j);
		}
	}
	cur++;
	for (int i : {1, 2, 3, 4})
		bfs(i, i-1);

	string Ans = "01234";

	if (none(3, 4, 2, 4, 1, 4, 1, 4))
		Ans[2] = Ans[1];
	if (none(3, 1, 3, 2, 3, 4, 3, 4))
		Ans[3] = Ans[2];
	if (none(1, 3, 2, 4, 3, 2, 1, 4))
		Ans[3] = Ans[1];
	if (none(1, 2, 1, 3, 1, 4, 1, 4))
		Ans[4] = Ans[3];
	if (none(1, 2, 3, 4, 1, 4, 2, 3))
		Ans[4] = Ans[2];
	if (none(2, 1, 2, 3, 2, 4, 2, 4))
		Ans[4] = Ans[1];

	for (int i=0;i<N * N;i++){
		nei[i].clear();
		seen[0][i] = seen[1][i] = seen[2][i] = seen[3][i] = 0;
	}
	return Ans;
}

int main(){
	cin>>n>>m>>w>>h;

	n += 4;
	for (int i=5;i<=n;i++)
		cin>>x[i]>>y[i]>>r[i];

	vector<pair<string, int>> vec;
	int r = 0, R = max(w, h), l, mid;
	while (r < R){
		l = r, r = R;
		string cur = get(l);
		while (l + 1 < r){
			mid = (l + r) / 2;
			if (get(mid) == cur)
				l = mid;
			else
				r = mid;
		}
		vec.push_back({cur, l});
		// cout<<cur<<" "<<l<<endl;
	}

	for (int i=1;i<=m;i++){
		int r, e;
		cin>>r>>e;

		int j = 0;
		while (vec[j].second < r)
			j++;
		for (int k : {1, 2, 3, 4}){
			if (vec[j].first[k] == vec[j].first[e])
				cout<<k;
		}
		cout<<'\n';

	}

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...