Submission #122860

# Submission time Handle Problem Language Result Execution time Memory
122860 2019-06-29T11:53:41 Z diamond_duke Circle selection (APIO18_circle_selection) C++11
100 / 100
1285 ms 37064 KB
#include <algorithm>
#include <cstdio>
#include <vector>
using ll = long long;
inline ll sqr(ll x) { return x * x; }
struct circle { int x, y, r; } arr[300005], val[300005];
bool operator <(circle a, circle b)
{
	if (a.x == b.x)
		return a.y < b.y;
	return a.x < b.x;
}
bool intersect(circle a, circle b) { return sqr(a.x - b.x) + sqr(a.y - b.y) <= sqr(a.r + b.r); }
int seq[300005], ans[300005];
std::vector<int> vec[300005];
int main()
{
	int n, rad = 0, len = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d%d", &arr[i].x, &arr[i].y, &arr[i].r);
		arr[i].x += 1e9;
		arr[i].y += 1e9;
		seq[i] = i;
		ans[i] = -1;
	}
	std::sort(seq, seq + n, [&] (int x, int y)
	{
		if (arr[x].r == arr[y].r)
			return x < y;
		return arr[x].r > arr[y].r;
	});
	auto resize = [&] ()
	{
		int cnt = 0;
		for (int i = 0; i < n; i++)
		{
			if (-1 == ans[i])
				val[cnt++] = {arr[i].x / rad, arr[i].y / rad, i};
		}
		std::sort(val, val + cnt);
		len = 0;
		for (int l = 0, r = 0; l < cnt; l = r)
		{
			while (r < cnt && val[l].x == val[r].x && val[l].y == val[r].y)
				r++;
			vec[len].clear();
			for (int i = l; i < r; i++)
				vec[len].push_back(val[i].r);
			val[len++] = val[l];
		}
	};
	for (int i = 0; i < n; i++)
	{
		int u = seq[i];
		if (~ans[u])
			continue;
		if (!rad || rad / 2 > arr[u].r)
		{
			rad = arr[u].r;
			resize();
		}
		int x = arr[u].x / rad, y = arr[u].y / rad;
		for (int xx = x - 2; xx <= x + 2; xx++)
		{
			for (int yy = y - 2; yy <= y + 2; yy++)
			{
				circle cur = {xx, yy, -1};
				int pos = std::lower_bound(val, val + len, cur) - val;
				if (pos >= len || val[pos].x != xx || val[pos].y != yy)
					continue;
				std::vector<int> nxt;
				for (int v : vec[pos])
				{
					if (intersect(arr[u], arr[v]))
						ans[v] = u;
					else
						nxt.push_back(v);
				}
				vec[pos] = nxt;
			}
		}
	}
	for (int i = 0; i < n; i++)
		printf("%d%c", ans[i] + 1, " \n"[i + 1 == n]);
	return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
circle_selection.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &arr[i].x, &arr[i].y, &arr[i].r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 7 ms 7416 KB Output is correct
3 Correct 7 ms 7356 KB Output is correct
4 Correct 7 ms 7416 KB Output is correct
5 Correct 7 ms 7416 KB Output is correct
6 Correct 7 ms 7416 KB Output is correct
7 Correct 7 ms 7416 KB Output is correct
8 Correct 7 ms 7416 KB Output is correct
9 Correct 8 ms 7416 KB Output is correct
10 Correct 9 ms 7416 KB Output is correct
11 Correct 8 ms 7416 KB Output is correct
12 Correct 8 ms 7416 KB Output is correct
13 Correct 8 ms 7388 KB Output is correct
14 Correct 7 ms 7416 KB Output is correct
15 Correct 7 ms 7416 KB Output is correct
16 Correct 8 ms 7460 KB Output is correct
17 Correct 8 ms 7416 KB Output is correct
18 Correct 8 ms 7416 KB Output is correct
19 Correct 12 ms 7644 KB Output is correct
20 Correct 11 ms 7628 KB Output is correct
21 Correct 12 ms 7544 KB Output is correct
22 Correct 20 ms 7672 KB Output is correct
23 Correct 22 ms 7672 KB Output is correct
24 Correct 20 ms 7672 KB Output is correct
25 Correct 20 ms 7672 KB Output is correct
26 Correct 20 ms 7672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 239 ms 20180 KB Output is correct
2 Correct 238 ms 20524 KB Output is correct
3 Correct 238 ms 19952 KB Output is correct
4 Correct 236 ms 20424 KB Output is correct
5 Correct 251 ms 20424 KB Output is correct
6 Correct 522 ms 28044 KB Output is correct
7 Correct 276 ms 25428 KB Output is correct
8 Correct 327 ms 25616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7416 KB Output is correct
2 Correct 357 ms 14184 KB Output is correct
3 Correct 1130 ms 36244 KB Output is correct
4 Correct 1208 ms 36276 KB Output is correct
5 Correct 979 ms 34124 KB Output is correct
6 Correct 403 ms 21244 KB Output is correct
7 Correct 199 ms 14712 KB Output is correct
8 Correct 39 ms 8824 KB Output is correct
9 Correct 1144 ms 35944 KB Output is correct
10 Correct 891 ms 34344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1018 ms 28144 KB Output is correct
2 Correct 925 ms 35192 KB Output is correct
3 Correct 332 ms 29832 KB Output is correct
4 Correct 927 ms 35704 KB Output is correct
5 Correct 918 ms 35812 KB Output is correct
6 Correct 259 ms 28556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 7 ms 7416 KB Output is correct
3 Correct 7 ms 7356 KB Output is correct
4 Correct 7 ms 7416 KB Output is correct
5 Correct 7 ms 7416 KB Output is correct
6 Correct 7 ms 7416 KB Output is correct
7 Correct 7 ms 7416 KB Output is correct
8 Correct 7 ms 7416 KB Output is correct
9 Correct 8 ms 7416 KB Output is correct
10 Correct 9 ms 7416 KB Output is correct
11 Correct 8 ms 7416 KB Output is correct
12 Correct 8 ms 7416 KB Output is correct
13 Correct 8 ms 7388 KB Output is correct
14 Correct 7 ms 7416 KB Output is correct
15 Correct 7 ms 7416 KB Output is correct
16 Correct 8 ms 7460 KB Output is correct
17 Correct 8 ms 7416 KB Output is correct
18 Correct 8 ms 7416 KB Output is correct
19 Correct 12 ms 7644 KB Output is correct
20 Correct 11 ms 7628 KB Output is correct
21 Correct 12 ms 7544 KB Output is correct
22 Correct 20 ms 7672 KB Output is correct
23 Correct 22 ms 7672 KB Output is correct
24 Correct 20 ms 7672 KB Output is correct
25 Correct 20 ms 7672 KB Output is correct
26 Correct 20 ms 7672 KB Output is correct
27 Correct 16 ms 7800 KB Output is correct
28 Correct 15 ms 7800 KB Output is correct
29 Correct 15 ms 7800 KB Output is correct
30 Correct 36 ms 8060 KB Output is correct
31 Correct 34 ms 8312 KB Output is correct
32 Correct 34 ms 8312 KB Output is correct
33 Correct 89 ms 14832 KB Output is correct
34 Correct 91 ms 14680 KB Output is correct
35 Correct 94 ms 14584 KB Output is correct
36 Correct 328 ms 16752 KB Output is correct
37 Correct 331 ms 16888 KB Output is correct
38 Correct 345 ms 17016 KB Output is correct
39 Correct 316 ms 17368 KB Output is correct
40 Correct 343 ms 16980 KB Output is correct
41 Correct 351 ms 17432 KB Output is correct
42 Correct 167 ms 15864 KB Output is correct
43 Correct 272 ms 16888 KB Output is correct
44 Correct 276 ms 16888 KB Output is correct
45 Correct 273 ms 16760 KB Output is correct
46 Correct 272 ms 16700 KB Output is correct
47 Correct 273 ms 16736 KB Output is correct
48 Correct 273 ms 16760 KB Output is correct
49 Correct 273 ms 16884 KB Output is correct
50 Correct 271 ms 16784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 7 ms 7416 KB Output is correct
3 Correct 7 ms 7356 KB Output is correct
4 Correct 7 ms 7416 KB Output is correct
5 Correct 7 ms 7416 KB Output is correct
6 Correct 7 ms 7416 KB Output is correct
7 Correct 7 ms 7416 KB Output is correct
8 Correct 7 ms 7416 KB Output is correct
9 Correct 8 ms 7416 KB Output is correct
10 Correct 9 ms 7416 KB Output is correct
11 Correct 8 ms 7416 KB Output is correct
12 Correct 8 ms 7416 KB Output is correct
13 Correct 8 ms 7388 KB Output is correct
14 Correct 7 ms 7416 KB Output is correct
15 Correct 7 ms 7416 KB Output is correct
16 Correct 8 ms 7460 KB Output is correct
17 Correct 8 ms 7416 KB Output is correct
18 Correct 8 ms 7416 KB Output is correct
19 Correct 12 ms 7644 KB Output is correct
20 Correct 11 ms 7628 KB Output is correct
21 Correct 12 ms 7544 KB Output is correct
22 Correct 20 ms 7672 KB Output is correct
23 Correct 22 ms 7672 KB Output is correct
24 Correct 20 ms 7672 KB Output is correct
25 Correct 20 ms 7672 KB Output is correct
26 Correct 20 ms 7672 KB Output is correct
27 Correct 239 ms 20180 KB Output is correct
28 Correct 238 ms 20524 KB Output is correct
29 Correct 238 ms 19952 KB Output is correct
30 Correct 236 ms 20424 KB Output is correct
31 Correct 251 ms 20424 KB Output is correct
32 Correct 522 ms 28044 KB Output is correct
33 Correct 276 ms 25428 KB Output is correct
34 Correct 327 ms 25616 KB Output is correct
35 Correct 7 ms 7416 KB Output is correct
36 Correct 357 ms 14184 KB Output is correct
37 Correct 1130 ms 36244 KB Output is correct
38 Correct 1208 ms 36276 KB Output is correct
39 Correct 979 ms 34124 KB Output is correct
40 Correct 403 ms 21244 KB Output is correct
41 Correct 199 ms 14712 KB Output is correct
42 Correct 39 ms 8824 KB Output is correct
43 Correct 1144 ms 35944 KB Output is correct
44 Correct 891 ms 34344 KB Output is correct
45 Correct 1018 ms 28144 KB Output is correct
46 Correct 925 ms 35192 KB Output is correct
47 Correct 332 ms 29832 KB Output is correct
48 Correct 927 ms 35704 KB Output is correct
49 Correct 918 ms 35812 KB Output is correct
50 Correct 259 ms 28556 KB Output is correct
51 Correct 16 ms 7800 KB Output is correct
52 Correct 15 ms 7800 KB Output is correct
53 Correct 15 ms 7800 KB Output is correct
54 Correct 36 ms 8060 KB Output is correct
55 Correct 34 ms 8312 KB Output is correct
56 Correct 34 ms 8312 KB Output is correct
57 Correct 89 ms 14832 KB Output is correct
58 Correct 91 ms 14680 KB Output is correct
59 Correct 94 ms 14584 KB Output is correct
60 Correct 328 ms 16752 KB Output is correct
61 Correct 331 ms 16888 KB Output is correct
62 Correct 345 ms 17016 KB Output is correct
63 Correct 316 ms 17368 KB Output is correct
64 Correct 343 ms 16980 KB Output is correct
65 Correct 351 ms 17432 KB Output is correct
66 Correct 167 ms 15864 KB Output is correct
67 Correct 272 ms 16888 KB Output is correct
68 Correct 276 ms 16888 KB Output is correct
69 Correct 273 ms 16760 KB Output is correct
70 Correct 272 ms 16700 KB Output is correct
71 Correct 273 ms 16736 KB Output is correct
72 Correct 273 ms 16760 KB Output is correct
73 Correct 273 ms 16884 KB Output is correct
74 Correct 271 ms 16784 KB Output is correct
75 Correct 273 ms 29384 KB Output is correct
76 Correct 264 ms 29376 KB Output is correct
77 Correct 253 ms 29028 KB Output is correct
78 Correct 265 ms 28904 KB Output is correct
79 Correct 294 ms 29256 KB Output is correct
80 Correct 277 ms 28992 KB Output is correct
81 Correct 1106 ms 36124 KB Output is correct
82 Correct 1119 ms 36008 KB Output is correct
83 Correct 1102 ms 35928 KB Output is correct
84 Correct 1133 ms 36472 KB Output is correct
85 Correct 1095 ms 36088 KB Output is correct
86 Correct 1094 ms 36088 KB Output is correct
87 Correct 1228 ms 36092 KB Output is correct
88 Correct 1070 ms 36860 KB Output is correct
89 Correct 1038 ms 37064 KB Output is correct
90 Correct 1071 ms 36776 KB Output is correct
91 Correct 1047 ms 35864 KB Output is correct
92 Correct 1053 ms 36016 KB Output is correct
93 Correct 951 ms 35140 KB Output is correct
94 Correct 990 ms 35524 KB Output is correct
95 Correct 957 ms 35064 KB Output is correct
96 Correct 962 ms 35192 KB Output is correct
97 Correct 1285 ms 34936 KB Output is correct
98 Correct 615 ms 32068 KB Output is correct
99 Correct 996 ms 35320 KB Output is correct
100 Correct 921 ms 34920 KB Output is correct
101 Correct 814 ms 33508 KB Output is correct
102 Correct 972 ms 35052 KB Output is correct
103 Correct 1235 ms 35008 KB Output is correct
104 Correct 981 ms 35064 KB Output is correct
105 Correct 578 ms 32888 KB Output is correct
106 Correct 816 ms 35312 KB Output is correct
107 Correct 802 ms 35364 KB Output is correct
108 Correct 820 ms 35320 KB Output is correct
109 Correct 809 ms 35320 KB Output is correct
110 Correct 805 ms 35320 KB Output is correct
111 Correct 822 ms 35320 KB Output is correct
112 Correct 823 ms 35268 KB Output is correct
113 Correct 816 ms 35276 KB Output is correct
114 Correct 808 ms 35312 KB Output is correct
115 Correct 807 ms 35280 KB Output is correct
116 Correct 789 ms 35332 KB Output is correct