Submission #728311

# Submission time Handle Problem Language Result Execution time Memory
728311 2023-04-22T07:17:17 Z SanguineChameleon Circle selection (APIO18_circle_selection) C++17
87 / 100
3000 ms 68880 KB
#include <bits/stdc++.h>
using namespace std;

void just_do_it();

int main() {
	#ifdef KAMIRULEZ
		freopen("kamirulez.inp", "r", stdin);
		freopen("kamirulez.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	just_do_it();
	return 0;
}

struct circle {
	int x, y, r;
};

bool intersect(circle C1, circle C2) {
	return 1LL * (C1.r + C2.r) * (C1.r + C2.r) >= 1LL * (C1.x - C2.x) * (C1.x - C2.x) + 1LL * (C1.y - C2.y) * (C1.y - C2.y); 
}

const int maxn = 3e5 + 20;
circle C[maxn];
int res[maxn];
set<pair<int, int>> S;
map<pair<int, int>, set<int>> groups;
int n;

int floor(int a, int b) {
	return (a / b) - (a % b && (a ^ b) < 0);
}

void build(int len) {
	groups.clear();
	for (auto p: S) {
		int i = p.second;
		int cx = floor(C[i].x, len);
		int cy = floor(C[i].y, len);
		groups[{cx, cy}].insert(i);
	}
}

void just_do_it() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> C[i].x >> C[i].y >> C[i].r;
		S.insert({-C[i].r, i});
	}
	int len = -1;
	while (!S.empty()) {
		int cur = S.begin()->second;
		if (len == -1 || 3.0 * C[cur].r < len) {
			len = C[cur].r;
			build(len);
		}
		int cx = floor(C[cur].x, len);
		int cy = floor(C[cur].y, len);
		for (int i = -2; i <= 2; i++) {
			for (int j = -2; j <= 2; j++) {
				auto g_it = groups.find({cx + i, cy + j});
				if (g_it == groups.end()) {
					continue;
				}
				auto it = g_it->second.begin();
				while (it != g_it->second.end()) {
					int can = *it;
					if (intersect(C[cur], C[can])) {
						res[can] = cur;
						it = g_it->second.erase(it);
						S.erase({-C[can].r, can});
					}
					else {
						it++;
					}
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << res[i] << " ";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 5 ms 936 KB Output is correct
20 Correct 6 ms 980 KB Output is correct
21 Correct 5 ms 952 KB Output is correct
22 Correct 13 ms 1492 KB Output is correct
23 Correct 14 ms 1492 KB Output is correct
24 Correct 12 ms 1492 KB Output is correct
25 Correct 12 ms 1476 KB Output is correct
26 Correct 13 ms 1476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 626 ms 35228 KB Output is correct
2 Correct 725 ms 35284 KB Output is correct
3 Correct 643 ms 35024 KB Output is correct
4 Correct 643 ms 35240 KB Output is correct
5 Correct 669 ms 35888 KB Output is correct
6 Correct 1020 ms 49312 KB Output is correct
7 Correct 790 ms 37016 KB Output is correct
8 Correct 736 ms 39540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 508 ms 21164 KB Output is correct
3 Correct 2033 ms 63276 KB Output is correct
4 Correct 1951 ms 63248 KB Output is correct
5 Correct 1894 ms 57220 KB Output is correct
6 Correct 778 ms 29192 KB Output is correct
7 Correct 317 ms 15728 KB Output is correct
8 Correct 33 ms 3496 KB Output is correct
9 Correct 2206 ms 62540 KB Output is correct
10 Correct 1987 ms 53416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1567 ms 63452 KB Output is correct
2 Correct 1085 ms 63312 KB Output is correct
3 Correct 797 ms 42828 KB Output is correct
4 Correct 1164 ms 63452 KB Output is correct
5 Correct 1124 ms 63368 KB Output is correct
6 Correct 730 ms 35976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 5 ms 936 KB Output is correct
20 Correct 6 ms 980 KB Output is correct
21 Correct 5 ms 952 KB Output is correct
22 Correct 13 ms 1492 KB Output is correct
23 Correct 14 ms 1492 KB Output is correct
24 Correct 12 ms 1492 KB Output is correct
25 Correct 12 ms 1476 KB Output is correct
26 Correct 13 ms 1476 KB Output is correct
27 Correct 10 ms 1748 KB Output is correct
28 Correct 11 ms 1764 KB Output is correct
29 Correct 10 ms 1748 KB Output is correct
30 Correct 37 ms 2636 KB Output is correct
31 Correct 26 ms 2624 KB Output is correct
32 Correct 29 ms 2636 KB Output is correct
33 Correct 165 ms 14964 KB Output is correct
34 Correct 137 ms 14864 KB Output is correct
35 Correct 208 ms 14828 KB Output is correct
36 Correct 477 ms 23768 KB Output is correct
37 Correct 437 ms 23848 KB Output is correct
38 Correct 474 ms 23812 KB Output is correct
39 Correct 738 ms 20916 KB Output is correct
40 Correct 762 ms 20956 KB Output is correct
41 Correct 769 ms 21016 KB Output is correct
42 Correct 298 ms 22768 KB Output is correct
43 Correct 296 ms 23652 KB Output is correct
44 Correct 299 ms 23572 KB Output is correct
45 Correct 296 ms 23560 KB Output is correct
46 Correct 303 ms 23624 KB Output is correct
47 Correct 303 ms 23572 KB Output is correct
48 Correct 325 ms 23620 KB Output is correct
49 Correct 327 ms 23720 KB Output is correct
50 Correct 312 ms 23580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 5 ms 936 KB Output is correct
20 Correct 6 ms 980 KB Output is correct
21 Correct 5 ms 952 KB Output is correct
22 Correct 13 ms 1492 KB Output is correct
23 Correct 14 ms 1492 KB Output is correct
24 Correct 12 ms 1492 KB Output is correct
25 Correct 12 ms 1476 KB Output is correct
26 Correct 13 ms 1476 KB Output is correct
27 Correct 626 ms 35228 KB Output is correct
28 Correct 725 ms 35284 KB Output is correct
29 Correct 643 ms 35024 KB Output is correct
30 Correct 643 ms 35240 KB Output is correct
31 Correct 669 ms 35888 KB Output is correct
32 Correct 1020 ms 49312 KB Output is correct
33 Correct 790 ms 37016 KB Output is correct
34 Correct 736 ms 39540 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 508 ms 21164 KB Output is correct
37 Correct 2033 ms 63276 KB Output is correct
38 Correct 1951 ms 63248 KB Output is correct
39 Correct 1894 ms 57220 KB Output is correct
40 Correct 778 ms 29192 KB Output is correct
41 Correct 317 ms 15728 KB Output is correct
42 Correct 33 ms 3496 KB Output is correct
43 Correct 2206 ms 62540 KB Output is correct
44 Correct 1987 ms 53416 KB Output is correct
45 Correct 1567 ms 63452 KB Output is correct
46 Correct 1085 ms 63312 KB Output is correct
47 Correct 797 ms 42828 KB Output is correct
48 Correct 1164 ms 63452 KB Output is correct
49 Correct 1124 ms 63368 KB Output is correct
50 Correct 730 ms 35976 KB Output is correct
51 Correct 10 ms 1748 KB Output is correct
52 Correct 11 ms 1764 KB Output is correct
53 Correct 10 ms 1748 KB Output is correct
54 Correct 37 ms 2636 KB Output is correct
55 Correct 26 ms 2624 KB Output is correct
56 Correct 29 ms 2636 KB Output is correct
57 Correct 165 ms 14964 KB Output is correct
58 Correct 137 ms 14864 KB Output is correct
59 Correct 208 ms 14828 KB Output is correct
60 Correct 477 ms 23768 KB Output is correct
61 Correct 437 ms 23848 KB Output is correct
62 Correct 474 ms 23812 KB Output is correct
63 Correct 738 ms 20916 KB Output is correct
64 Correct 762 ms 20956 KB Output is correct
65 Correct 769 ms 21016 KB Output is correct
66 Correct 298 ms 22768 KB Output is correct
67 Correct 296 ms 23652 KB Output is correct
68 Correct 299 ms 23572 KB Output is correct
69 Correct 296 ms 23560 KB Output is correct
70 Correct 303 ms 23624 KB Output is correct
71 Correct 303 ms 23572 KB Output is correct
72 Correct 325 ms 23620 KB Output is correct
73 Correct 327 ms 23720 KB Output is correct
74 Correct 312 ms 23580 KB Output is correct
75 Correct 750 ms 41592 KB Output is correct
76 Correct 663 ms 41676 KB Output is correct
77 Correct 659 ms 41820 KB Output is correct
78 Correct 699 ms 41312 KB Output is correct
79 Correct 872 ms 41616 KB Output is correct
80 Correct 592 ms 41032 KB Output is correct
81 Correct 1915 ms 68880 KB Output is correct
82 Correct 1948 ms 68512 KB Output is correct
83 Correct 1820 ms 68508 KB Output is correct
84 Correct 2048 ms 68360 KB Output is correct
85 Correct 1977 ms 68260 KB Output is correct
86 Correct 1921 ms 68300 KB Output is correct
87 Correct 2158 ms 67992 KB Output is correct
88 Execution timed out 3086 ms 60528 KB Time limit exceeded
89 Halted 0 ms 0 KB -