답안 #902378

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
902378 2024-01-10T10:40:48 Z Trisanu_Das 원 고르기 (APIO18_circle_selection) C++17
100 / 100
2595 ms 63380 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const int N = (int)3e5+ 7;
 
int x[N], y[N], r[N], n, ans[N], pos[N], block = 0;
map<pair<int, int>, vector<int>> mp;
set <int> ost;
 
ll sqr(ll x) {
	return x * x;
}
 
ll dist(int x1, int y1, int x2, int y2) {
	return sqr(x1 - x2) + sqr(y1 - y2);
}
 
void rescale() {
	mp.clear();
	for (int to : ost) mp[{x[to] / block, y[to] / block}].push_back(to);
}
 
main() {
	iota(pos, pos + N, 0);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d %d", &x[i], &y[i], &r[i]);
		ost.insert(i);
	}
	sort(pos + 1, pos + n + 1, [&](const int &A, const int &B) {
		if (r[A] == r[B]) return A < B;
		return r[A] > r[B];
	});
	for (int i = 1; i <= n; i++) {
		if (ans[pos[i]]) continue;
		if (block == 0 || r[pos[i]] * 2 <= block) {
			block = r[pos[i]];
			rescale();
		}
		for (int cx = x[pos[i]] / block - 2; cx <= x[pos[i]] / block + 2; cx++) {
			for (int cy = y[pos[i]] / block - 2; cy <= y[pos[i]] / block + 2; cy++) {
				if (!mp.count({cx, cy})) continue;
				for (int to : mp[{cx, cy}]) {
					if (!ans[to] && dist(x[pos[i]], y[pos[i]], x[to], y[to]) <= sqr(r[pos[i]] + r[to])) {
						ans[to] = pos[i];
						ost.erase(to);
					}
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}

Compilation message

circle_selection.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   24 | main() {
      | ^~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
circle_selection.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   scanf("%d %d %d", &x[i], &y[i], &r[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4712 KB Output is correct
3 Correct 1 ms 4712 KB Output is correct
4 Correct 1 ms 4720 KB Output is correct
5 Correct 1 ms 4720 KB Output is correct
6 Correct 1 ms 4704 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4708 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4712 KB Output is correct
13 Correct 1 ms 4704 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 2 ms 4776 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 2 ms 4772 KB Output is correct
19 Correct 6 ms 4952 KB Output is correct
20 Correct 4 ms 4968 KB Output is correct
21 Correct 6 ms 4968 KB Output is correct
22 Correct 15 ms 5480 KB Output is correct
23 Correct 15 ms 5656 KB Output is correct
24 Correct 13 ms 5480 KB Output is correct
25 Correct 12 ms 5480 KB Output is correct
26 Correct 13 ms 5480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 29152 KB Output is correct
2 Correct 258 ms 30172 KB Output is correct
3 Correct 232 ms 29972 KB Output is correct
4 Correct 211 ms 29224 KB Output is correct
5 Correct 410 ms 29780 KB Output is correct
6 Correct 1004 ms 43024 KB Output is correct
7 Correct 470 ms 31008 KB Output is correct
8 Correct 584 ms 33364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 553 ms 24068 KB Output is correct
3 Correct 2213 ms 63140 KB Output is correct
4 Correct 2257 ms 63132 KB Output is correct
5 Correct 2214 ms 56492 KB Output is correct
6 Correct 678 ms 30424 KB Output is correct
7 Correct 308 ms 18344 KB Output is correct
8 Correct 34 ms 7540 KB Output is correct
9 Correct 2595 ms 62260 KB Output is correct
10 Correct 1991 ms 55480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1565 ms 58876 KB Output is correct
2 Correct 1088 ms 62124 KB Output is correct
3 Correct 700 ms 40484 KB Output is correct
4 Correct 1148 ms 62676 KB Output is correct
5 Correct 1150 ms 62872 KB Output is correct
6 Correct 436 ms 34116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4712 KB Output is correct
3 Correct 1 ms 4712 KB Output is correct
4 Correct 1 ms 4720 KB Output is correct
5 Correct 1 ms 4720 KB Output is correct
6 Correct 1 ms 4704 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4708 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4712 KB Output is correct
13 Correct 1 ms 4704 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 2 ms 4776 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 2 ms 4772 KB Output is correct
19 Correct 6 ms 4952 KB Output is correct
20 Correct 4 ms 4968 KB Output is correct
21 Correct 6 ms 4968 KB Output is correct
22 Correct 15 ms 5480 KB Output is correct
23 Correct 15 ms 5656 KB Output is correct
24 Correct 13 ms 5480 KB Output is correct
25 Correct 12 ms 5480 KB Output is correct
26 Correct 13 ms 5480 KB Output is correct
27 Correct 7 ms 5212 KB Output is correct
28 Correct 7 ms 5212 KB Output is correct
29 Correct 11 ms 5212 KB Output is correct
30 Correct 30 ms 6236 KB Output is correct
31 Correct 27 ms 6232 KB Output is correct
32 Correct 30 ms 6324 KB Output is correct
33 Correct 82 ms 10956 KB Output is correct
34 Correct 77 ms 10808 KB Output is correct
35 Correct 77 ms 10396 KB Output is correct
36 Correct 429 ms 21072 KB Output is correct
37 Correct 501 ms 21076 KB Output is correct
38 Correct 454 ms 21404 KB Output is correct
39 Correct 332 ms 19572 KB Output is correct
40 Correct 389 ms 20084 KB Output is correct
41 Correct 344 ms 19520 KB Output is correct
42 Correct 292 ms 21360 KB Output is correct
43 Correct 300 ms 21060 KB Output is correct
44 Correct 332 ms 21076 KB Output is correct
45 Correct 315 ms 21284 KB Output is correct
46 Correct 304 ms 21000 KB Output is correct
47 Correct 335 ms 20996 KB Output is correct
48 Correct 322 ms 21000 KB Output is correct
49 Correct 314 ms 21076 KB Output is correct
50 Correct 276 ms 21076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4712 KB Output is correct
3 Correct 1 ms 4712 KB Output is correct
4 Correct 1 ms 4720 KB Output is correct
5 Correct 1 ms 4720 KB Output is correct
6 Correct 1 ms 4704 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4708 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4712 KB Output is correct
13 Correct 1 ms 4704 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 2 ms 4776 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 2 ms 4772 KB Output is correct
19 Correct 6 ms 4952 KB Output is correct
20 Correct 4 ms 4968 KB Output is correct
21 Correct 6 ms 4968 KB Output is correct
22 Correct 15 ms 5480 KB Output is correct
23 Correct 15 ms 5656 KB Output is correct
24 Correct 13 ms 5480 KB Output is correct
25 Correct 12 ms 5480 KB Output is correct
26 Correct 13 ms 5480 KB Output is correct
27 Correct 226 ms 29152 KB Output is correct
28 Correct 258 ms 30172 KB Output is correct
29 Correct 232 ms 29972 KB Output is correct
30 Correct 211 ms 29224 KB Output is correct
31 Correct 410 ms 29780 KB Output is correct
32 Correct 1004 ms 43024 KB Output is correct
33 Correct 470 ms 31008 KB Output is correct
34 Correct 584 ms 33364 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 553 ms 24068 KB Output is correct
37 Correct 2213 ms 63140 KB Output is correct
38 Correct 2257 ms 63132 KB Output is correct
39 Correct 2214 ms 56492 KB Output is correct
40 Correct 678 ms 30424 KB Output is correct
41 Correct 308 ms 18344 KB Output is correct
42 Correct 34 ms 7540 KB Output is correct
43 Correct 2595 ms 62260 KB Output is correct
44 Correct 1991 ms 55480 KB Output is correct
45 Correct 1565 ms 58876 KB Output is correct
46 Correct 1088 ms 62124 KB Output is correct
47 Correct 700 ms 40484 KB Output is correct
48 Correct 1148 ms 62676 KB Output is correct
49 Correct 1150 ms 62872 KB Output is correct
50 Correct 436 ms 34116 KB Output is correct
51 Correct 7 ms 5212 KB Output is correct
52 Correct 7 ms 5212 KB Output is correct
53 Correct 11 ms 5212 KB Output is correct
54 Correct 30 ms 6236 KB Output is correct
55 Correct 27 ms 6232 KB Output is correct
56 Correct 30 ms 6324 KB Output is correct
57 Correct 82 ms 10956 KB Output is correct
58 Correct 77 ms 10808 KB Output is correct
59 Correct 77 ms 10396 KB Output is correct
60 Correct 429 ms 21072 KB Output is correct
61 Correct 501 ms 21076 KB Output is correct
62 Correct 454 ms 21404 KB Output is correct
63 Correct 332 ms 19572 KB Output is correct
64 Correct 389 ms 20084 KB Output is correct
65 Correct 344 ms 19520 KB Output is correct
66 Correct 292 ms 21360 KB Output is correct
67 Correct 300 ms 21060 KB Output is correct
68 Correct 332 ms 21076 KB Output is correct
69 Correct 315 ms 21284 KB Output is correct
70 Correct 304 ms 21000 KB Output is correct
71 Correct 335 ms 20996 KB Output is correct
72 Correct 322 ms 21000 KB Output is correct
73 Correct 314 ms 21076 KB Output is correct
74 Correct 276 ms 21076 KB Output is correct
75 Correct 270 ms 32168 KB Output is correct
76 Correct 255 ms 31468 KB Output is correct
77 Correct 226 ms 32988 KB Output is correct
78 Correct 229 ms 32520 KB Output is correct
79 Correct 392 ms 31380 KB Output is correct
80 Correct 213 ms 32516 KB Output is correct
81 Correct 2265 ms 63100 KB Output is correct
82 Correct 2178 ms 62932 KB Output is correct
83 Correct 2164 ms 62872 KB Output is correct
84 Correct 2411 ms 63380 KB Output is correct
85 Correct 2094 ms 62948 KB Output is correct
86 Correct 2015 ms 62776 KB Output is correct
87 Correct 2396 ms 62908 KB Output is correct
88 Correct 1480 ms 53672 KB Output is correct
89 Correct 1356 ms 53632 KB Output is correct
90 Correct 1483 ms 53696 KB Output is correct
91 Correct 1513 ms 53452 KB Output is correct
92 Correct 1519 ms 53660 KB Output is correct
93 Correct 1537 ms 61952 KB Output is correct
94 Correct 1715 ms 62128 KB Output is correct
95 Correct 1472 ms 61940 KB Output is correct
96 Correct 1650 ms 61964 KB Output is correct
97 Correct 2294 ms 61880 KB Output is correct
98 Correct 1176 ms 50200 KB Output is correct
99 Correct 1654 ms 62124 KB Output is correct
100 Correct 1330 ms 61884 KB Output is correct
101 Correct 1578 ms 55340 KB Output is correct
102 Correct 1657 ms 61556 KB Output is correct
103 Correct 2371 ms 61816 KB Output is correct
104 Correct 1686 ms 61820 KB Output is correct
105 Correct 1392 ms 59640 KB Output is correct
106 Correct 1081 ms 60628 KB Output is correct
107 Correct 1156 ms 60932 KB Output is correct
108 Correct 1115 ms 60408 KB Output is correct
109 Correct 1143 ms 60720 KB Output is correct
110 Correct 1172 ms 60928 KB Output is correct
111 Correct 1092 ms 60808 KB Output is correct
112 Correct 1136 ms 60880 KB Output is correct
113 Correct 1140 ms 60884 KB Output is correct
114 Correct 1142 ms 60828 KB Output is correct
115 Correct 1117 ms 60824 KB Output is correct
116 Correct 1041 ms 60876 KB Output is correct