Submission #1066832

# Submission time Handle Problem Language Result Execution time Memory
1066832 2024-08-20T07:51:38 Z kunzaZa183 Park (BOI16_park) C++17
100 / 100
256 ms 54420 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int par(int cur, vector<int>& ds) {
	if (ds[cur] == cur)
		return cur;
	ds[cur] = par(ds[cur], ds);
	return ds[cur];
};

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	int w, h;
	cin >> w >> h;

	struct tree {
		int x, y, r;
	};
	vector<tree> vt(n);
	for (auto& a : vt)
		cin >> a.x >> a.y >> a.r;

	struct edge {
		int a, b, w;
		edge() {}
		edge(int x, int y, int z) {
			a = x, b = y, w = z;
		}
	};

	auto dis = [](tree a, tree b) {
		return int64_t(sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) + 1e-5) - a.r - b.r;
	};

	vector<edge> ve;
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++) {
			ve.emplace_back(i, j, dis(vt[i], vt[j]));
		}

	for (int i = 0; i < n; i++) {
		ve.emplace_back(i, n, vt[i].y - vt[i].r);
		ve.emplace_back(i, n + 1, w - vt[i].x - vt[i].r);
		ve.emplace_back(i, n + 2, vt[i].x - vt[i].r);
		ve.emplace_back(i, n + 3, h - vt[i].y - vt[i].r);
	}

	sort(ve.begin(), ve.end(), [&](edge a, edge b) {
		return a.w < b.w;
		});

	int alive[4][4];

	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 4; j++)
			alive[i][j] = 1;

	auto kill = [&](vector<int> vi, vector<int> vi2) {

		for (auto a : vi)
			for (auto b : vi2)
				alive[a][b] = 0;

		for (auto a : vi2)
			for (auto b : vi)
				alive[a][b] = 0;
	};

	struct qry {
		int r, start;
		int in;
	};
	vector<qry> vq(m);
	for (int i = 0; i < m; i++) {
		cin >> vq[i].r >> vq[i].start;
		vq[i].in = i;
		vq[i].start--;
	}
	sort(vq.begin(), vq.end(), [](qry a, qry b) {
		return a.r < b.r;
		});

	vector<int> dsu(n + 4);
	iota(dsu.begin(), dsu.end(), 0);


	vector<string> ans(m);

	int in = 0, in2 = 0;
	while (in < ve.size() && in2 < m) {
		if (vq[in2].r * 2 <= ve[in].w) {
			vector<int> ds2(4);
			iota(ds2.begin(), ds2.end(), 0);

			for (int i = 0; i < 4; i++)
				for (int j = 0; j < 4; j++)
					if (alive[i][j])
						ds2[par(i, ds2)] = par(j, ds2);

			for (int i = 0; i < 4; i++)
				if (par(i, ds2) == par(vq[in2].start, ds2)) {
					ans[vq[in2].in].push_back('1' + i);
				}

			in2++;
		}
		else {
			dsu[par(ve[in].a, dsu)] = par(ve[in].b, dsu);

			if (par(n, dsu) == par(n + 3, dsu))
				kill({ 0, 3 }, { 1, 2 });
			if (par(n + 1, dsu) == par(n + 2, dsu))
				kill({ 0,1 }, { 2,3 });
			if (par(n, dsu) == par(n + 1, dsu))
				kill({ 1 }, { 0,2,3 });
			if (par(n, dsu) == par(n + 2, dsu))
				kill({ 0 }, { 1,2,3 });
			if (par(n + 2, dsu) == par(n + 3, dsu))
				kill({ 3 }, { 0,1,2 });
			if (par(n + 1, dsu) == par(n + 3, dsu))
				kill({ 2 }, { 0,1,3 });
			in++;
		}
	}

	while (in2 < m) {
		vector<int> ds2(4);
		iota(ds2.begin(), ds2.end(), 0);

		for (int i = 0; i < 4; i++)
			for (int j = 0; j < 4; j++)
				if (alive[i][j])
					ds2[par(i, ds2)] = par(j, ds2);

		for (int i = 0; i < 4; i++)
			if (par(i, ds2) == par(vq[in2].start, ds2)) {
				ans[vq[in2].in].push_back('1' + i);
			}

		in2++;
	}

	for (auto a : ans)
		cout << a << "\n";

}

Compilation message

park.cpp: In function 'int main()':
park.cpp:93:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<main()::edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |  while (in < ve.size() && in2 < m) {
      |         ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 207 ms 49848 KB Output is correct
2 Correct 192 ms 49856 KB Output is correct
3 Correct 187 ms 49856 KB Output is correct
4 Correct 197 ms 49824 KB Output is correct
5 Correct 192 ms 49824 KB Output is correct
6 Correct 225 ms 49848 KB Output is correct
7 Correct 226 ms 49848 KB Output is correct
8 Correct 192 ms 49780 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7800 KB Output is correct
2 Correct 35 ms 7880 KB Output is correct
3 Correct 32 ms 7884 KB Output is correct
4 Correct 32 ms 7884 KB Output is correct
5 Correct 34 ms 7880 KB Output is correct
6 Correct 33 ms 7888 KB Output is correct
7 Correct 28 ms 7252 KB Output is correct
8 Correct 30 ms 7256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 49848 KB Output is correct
2 Correct 192 ms 49856 KB Output is correct
3 Correct 187 ms 49856 KB Output is correct
4 Correct 197 ms 49824 KB Output is correct
5 Correct 192 ms 49824 KB Output is correct
6 Correct 225 ms 49848 KB Output is correct
7 Correct 226 ms 49848 KB Output is correct
8 Correct 192 ms 49780 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 35 ms 7800 KB Output is correct
12 Correct 35 ms 7880 KB Output is correct
13 Correct 32 ms 7884 KB Output is correct
14 Correct 32 ms 7884 KB Output is correct
15 Correct 34 ms 7880 KB Output is correct
16 Correct 33 ms 7888 KB Output is correct
17 Correct 28 ms 7252 KB Output is correct
18 Correct 30 ms 7256 KB Output is correct
19 Correct 232 ms 54352 KB Output is correct
20 Correct 222 ms 54368 KB Output is correct
21 Correct 227 ms 54420 KB Output is correct
22 Correct 219 ms 54396 KB Output is correct
23 Correct 218 ms 54356 KB Output is correct
24 Correct 256 ms 54356 KB Output is correct