답안 #111274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111274 2019-05-14T14:54:40 Z diamond_duke 원 고르기 (APIO18_circle_selection) C++11
100 / 100
1370 ms 28400 KB
#include <algorithm>
#include <cstdio>
#include <vector>
using ll = long long;
inline ll sqr(int x) { return (ll)x * x; }
struct circle { int x, y, r; } arr[300005], seq[300005];
inline bool operator <(const circle &a, const circle &b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
inline bool operator !=(const circle &a, const circle &b) { return a < b || b < a; }
inline bool operator ==(const circle &a, const circle &b) { return !(a != b); }
inline bool inter(circle a, circle b) { return sqr(a.x - b.x) + sqr(a.y - b.y) <= sqr(a.r + b.r); }
int ans[300005], ord[300005], n, blk, len;
std::vector<int> vec[300005];
void resize(int sz)
{
	if (blk && blk / 2 < sz)
		return;
	blk = sz;
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (-1 == ans[i])
			seq[cnt++] = {arr[i].x / blk, arr[i].y / blk, i};
	}
	std::sort(seq, seq + cnt);
	len = 0;
	for (int i = 0, j = 0; i < cnt; i = j)
	{
		while (j < cnt && seq[i] == seq[j])
			j++;
		vec[len].clear();
		for (int k = i; k < j; k++)
			vec[len].push_back(seq[k].r);
		seq[len++] = seq[i];
	}
}
int main()
{
	// freopen("uoj-415.in", "r", stdin);
	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;
		ord[i] = i;
		ans[i] = -1;
	}
	std::sort(ord, ord + n, [&] (int x, int y) { return arr[x].r > arr[y].r || (arr[x].r == arr[y].r && x < y); });
	for (int t = 0; t < n; t++)
	{
		int u = ord[t];
		if (~ans[u])
			continue;
		resize(arr[u].r);
		int x = arr[u].x / blk, y = arr[u].y / blk;
		for (int i = x - 2; i <= x + 2; i++)
		{
			for (int j = y - 2; j <= y + 2; j++)
			{
				circle cur = {i, j, -1};
				int res = std::lower_bound(seq, seq + len, cur) - seq;
				if (res >= len || seq[res] != cur)
					continue;
				std::vector<int> rem;
				for (int v : vec[res])
				{
					if (inter(arr[u], arr[v]))
						ans[v] = u;
					else
						rem.push_back(v);
				}
				std::swap(vec[res], rem);
			}
		}
	}
	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:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
circle_selection.cpp:42: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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7396 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 7 ms 7424 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 10 ms 7424 KB Output is correct
11 Correct 9 ms 7424 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 7 ms 7424 KB Output is correct
14 Correct 8 ms 7424 KB Output is correct
15 Correct 8 ms 7424 KB Output is correct
16 Correct 8 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 10 ms 7424 KB Output is correct
19 Correct 15 ms 7680 KB Output is correct
20 Correct 15 ms 7680 KB Output is correct
21 Correct 15 ms 7552 KB Output is correct
22 Correct 20 ms 7680 KB Output is correct
23 Correct 21 ms 7680 KB Output is correct
24 Correct 27 ms 7680 KB Output is correct
25 Correct 24 ms 7680 KB Output is correct
26 Correct 20 ms 7680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 241 ms 18892 KB Output is correct
2 Correct 349 ms 19092 KB Output is correct
3 Correct 236 ms 19048 KB Output is correct
4 Correct 241 ms 19288 KB Output is correct
5 Correct 239 ms 20444 KB Output is correct
6 Correct 598 ms 23496 KB Output is correct
7 Correct 279 ms 20600 KB Output is correct
8 Correct 322 ms 21108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7452 KB Output is correct
2 Correct 318 ms 14200 KB Output is correct
3 Correct 1137 ms 28280 KB Output is correct
4 Correct 1078 ms 28156 KB Output is correct
5 Correct 1043 ms 26016 KB Output is correct
6 Correct 406 ms 16888 KB Output is correct
7 Correct 183 ms 12408 KB Output is correct
8 Correct 40 ms 8440 KB Output is correct
9 Correct 1111 ms 27940 KB Output is correct
10 Correct 844 ms 25848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 992 ms 28096 KB Output is correct
2 Correct 825 ms 28140 KB Output is correct
3 Correct 365 ms 21440 KB Output is correct
4 Correct 917 ms 28216 KB Output is correct
5 Correct 842 ms 28096 KB Output is correct
6 Correct 259 ms 20100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7396 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 7 ms 7424 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 10 ms 7424 KB Output is correct
11 Correct 9 ms 7424 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 7 ms 7424 KB Output is correct
14 Correct 8 ms 7424 KB Output is correct
15 Correct 8 ms 7424 KB Output is correct
16 Correct 8 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 10 ms 7424 KB Output is correct
19 Correct 15 ms 7680 KB Output is correct
20 Correct 15 ms 7680 KB Output is correct
21 Correct 15 ms 7552 KB Output is correct
22 Correct 20 ms 7680 KB Output is correct
23 Correct 21 ms 7680 KB Output is correct
24 Correct 27 ms 7680 KB Output is correct
25 Correct 24 ms 7680 KB Output is correct
26 Correct 20 ms 7680 KB Output is correct
27 Correct 16 ms 7808 KB Output is correct
28 Correct 15 ms 7808 KB Output is correct
29 Correct 17 ms 7808 KB Output is correct
30 Correct 33 ms 8056 KB Output is correct
31 Correct 29 ms 8064 KB Output is correct
32 Correct 32 ms 8064 KB Output is correct
33 Correct 92 ms 11256 KB Output is correct
34 Correct 93 ms 11168 KB Output is correct
35 Correct 90 ms 11248 KB Output is correct
36 Correct 368 ms 14188 KB Output is correct
37 Correct 362 ms 14248 KB Output is correct
38 Correct 375 ms 14200 KB Output is correct
39 Correct 323 ms 14200 KB Output is correct
40 Correct 322 ms 14240 KB Output is correct
41 Correct 378 ms 14304 KB Output is correct
42 Correct 193 ms 14204 KB Output is correct
43 Correct 257 ms 14188 KB Output is correct
44 Correct 237 ms 14192 KB Output is correct
45 Correct 288 ms 14200 KB Output is correct
46 Correct 262 ms 14120 KB Output is correct
47 Correct 241 ms 14184 KB Output is correct
48 Correct 266 ms 14164 KB Output is correct
49 Correct 252 ms 14220 KB Output is correct
50 Correct 325 ms 14200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7396 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 7 ms 7424 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 10 ms 7424 KB Output is correct
11 Correct 9 ms 7424 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 7 ms 7424 KB Output is correct
14 Correct 8 ms 7424 KB Output is correct
15 Correct 8 ms 7424 KB Output is correct
16 Correct 8 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 10 ms 7424 KB Output is correct
19 Correct 15 ms 7680 KB Output is correct
20 Correct 15 ms 7680 KB Output is correct
21 Correct 15 ms 7552 KB Output is correct
22 Correct 20 ms 7680 KB Output is correct
23 Correct 21 ms 7680 KB Output is correct
24 Correct 27 ms 7680 KB Output is correct
25 Correct 24 ms 7680 KB Output is correct
26 Correct 20 ms 7680 KB Output is correct
27 Correct 241 ms 18892 KB Output is correct
28 Correct 349 ms 19092 KB Output is correct
29 Correct 236 ms 19048 KB Output is correct
30 Correct 241 ms 19288 KB Output is correct
31 Correct 239 ms 20444 KB Output is correct
32 Correct 598 ms 23496 KB Output is correct
33 Correct 279 ms 20600 KB Output is correct
34 Correct 322 ms 21108 KB Output is correct
35 Correct 9 ms 7452 KB Output is correct
36 Correct 318 ms 14200 KB Output is correct
37 Correct 1137 ms 28280 KB Output is correct
38 Correct 1078 ms 28156 KB Output is correct
39 Correct 1043 ms 26016 KB Output is correct
40 Correct 406 ms 16888 KB Output is correct
41 Correct 183 ms 12408 KB Output is correct
42 Correct 40 ms 8440 KB Output is correct
43 Correct 1111 ms 27940 KB Output is correct
44 Correct 844 ms 25848 KB Output is correct
45 Correct 992 ms 28096 KB Output is correct
46 Correct 825 ms 28140 KB Output is correct
47 Correct 365 ms 21440 KB Output is correct
48 Correct 917 ms 28216 KB Output is correct
49 Correct 842 ms 28096 KB Output is correct
50 Correct 259 ms 20100 KB Output is correct
51 Correct 16 ms 7808 KB Output is correct
52 Correct 15 ms 7808 KB Output is correct
53 Correct 17 ms 7808 KB Output is correct
54 Correct 33 ms 8056 KB Output is correct
55 Correct 29 ms 8064 KB Output is correct
56 Correct 32 ms 8064 KB Output is correct
57 Correct 92 ms 11256 KB Output is correct
58 Correct 93 ms 11168 KB Output is correct
59 Correct 90 ms 11248 KB Output is correct
60 Correct 368 ms 14188 KB Output is correct
61 Correct 362 ms 14248 KB Output is correct
62 Correct 375 ms 14200 KB Output is correct
63 Correct 323 ms 14200 KB Output is correct
64 Correct 322 ms 14240 KB Output is correct
65 Correct 378 ms 14304 KB Output is correct
66 Correct 193 ms 14204 KB Output is correct
67 Correct 257 ms 14188 KB Output is correct
68 Correct 237 ms 14192 KB Output is correct
69 Correct 288 ms 14200 KB Output is correct
70 Correct 262 ms 14120 KB Output is correct
71 Correct 241 ms 14184 KB Output is correct
72 Correct 266 ms 14164 KB Output is correct
73 Correct 252 ms 14220 KB Output is correct
74 Correct 325 ms 14200 KB Output is correct
75 Correct 230 ms 19036 KB Output is correct
76 Correct 240 ms 19600 KB Output is correct
77 Correct 254 ms 18984 KB Output is correct
78 Correct 242 ms 19084 KB Output is correct
79 Correct 320 ms 19620 KB Output is correct
80 Correct 242 ms 19172 KB Output is correct
81 Correct 1194 ms 28096 KB Output is correct
82 Correct 1147 ms 28084 KB Output is correct
83 Correct 1113 ms 28156 KB Output is correct
84 Correct 1185 ms 28180 KB Output is correct
85 Correct 1100 ms 28104 KB Output is correct
86 Correct 1181 ms 28096 KB Output is correct
87 Correct 1255 ms 28144 KB Output is correct
88 Correct 1170 ms 28332 KB Output is correct
89 Correct 1122 ms 28400 KB Output is correct
90 Correct 1132 ms 28348 KB Output is correct
91 Correct 1124 ms 27868 KB Output is correct
92 Correct 1186 ms 28288 KB Output is correct
93 Correct 952 ms 28152 KB Output is correct
94 Correct 1103 ms 28032 KB Output is correct
95 Correct 1035 ms 28024 KB Output is correct
96 Correct 1002 ms 28084 KB Output is correct
97 Correct 1370 ms 28092 KB Output is correct
98 Correct 640 ms 24640 KB Output is correct
99 Correct 933 ms 28116 KB Output is correct
100 Correct 919 ms 28016 KB Output is correct
101 Correct 905 ms 26084 KB Output is correct
102 Correct 937 ms 27956 KB Output is correct
103 Correct 1232 ms 27964 KB Output is correct
104 Correct 971 ms 28120 KB Output is correct
105 Correct 693 ms 27812 KB Output is correct
106 Correct 866 ms 27356 KB Output is correct
107 Correct 840 ms 27348 KB Output is correct
108 Correct 797 ms 27348 KB Output is correct
109 Correct 893 ms 27480 KB Output is correct
110 Correct 831 ms 27344 KB Output is correct
111 Correct 759 ms 27464 KB Output is correct
112 Correct 860 ms 27348 KB Output is correct
113 Correct 849 ms 27488 KB Output is correct
114 Correct 774 ms 27348 KB Output is correct
115 Correct 795 ms 27352 KB Output is correct
116 Correct 764 ms 27404 KB Output is correct