Submission #244607

# Submission time Handle Problem Language Result Execution time Memory
244607 2020-07-04T12:06:07 Z maximath_1 Circle selection (APIO18_circle_selection) C++11
100 / 100
1549 ms 43532 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
int n, cr = 2000000069, id[300005];
vector<int> ans;
unordered_map<ll, vector<int> >grid;

ll sqr(ll x){return x *1ll* x;}

struct circ{int x, y, r;} a[300005];
bool intersect(circ aa, circ b){return sqr(aa.x - b.x) + sqr(aa.y - b.y) <= sqr(aa.r + b.r);}

void build(int sz){
	grid.clear();
	for(int i = 1; i <= n; i ++) if(!ans[i]){
		int cx = a[i].x / sz, cy = a[i].y / sz;
		grid[cx * 2000000069ll + cy].push_back(i);
	}
	return;
}

void solve(ll ps, int nw){
	if(!grid.count(ps)) return;

	for(int i = 0; i < grid[ps].size(); i ++){
		if(intersect(a[grid[ps][i]], a[nw])){
			ans[grid[ps][i]] = nw;
			swap(grid[ps][i--], grid[ps].back());
			grid[ps].pop_back();
		}
	}

	if(grid[ps].empty()) grid.erase(ps);
	return;
}

bool cmp(int i, int j){
	if(a[i].r == a[j].r)
		return i < j;
	return a[i].r > a[j].r;
}

int main(){
	scanf("%d", &n);
	ans.resize(n + 1);
	for(int i = 1; i <= n; i ++){
		scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].r);
		id[i] = i;
		a[i].x += 1000000000; a[i].y += 1000000000;
	}
	sort(id + 1, id + n + 1, cmp);

	for(int i = 1; i <= n; i ++) if(!ans[id[i]]){
		int nw = id[i];
		if(a[nw].r <= cr / 2){
			cr = a[nw].r;
			build(cr);
		}
		int nwx = a[nw].x / cr, nwy = a[nw].y / cr;
		for(int nxx = nwx - 2; nxx <= nwx + 2; nxx ++)
			for(int nxy = nwy - 2; nxy <= nwy + 2; nxy ++)
				solve(nxx * 2000000069ll + nxy, nw);
	}

	for(int i = 1; i <= n; i ++)
		printf("%d%c", ans[i], (i == n ? '\n' : ' '));
	return 0;
}

Compilation message

circle_selection.cpp: In function 'void solve(long long int, int)':
circle_selection.cpp:26:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < grid[ps].size(); i ++){
                 ~~^~~~~~~~~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
circle_selection.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 10 ms 768 KB Output is correct
20 Correct 9 ms 640 KB Output is correct
21 Correct 10 ms 768 KB Output is correct
22 Correct 17 ms 1024 KB Output is correct
23 Correct 14 ms 1024 KB Output is correct
24 Correct 15 ms 1024 KB Output is correct
25 Correct 14 ms 1024 KB Output is correct
26 Correct 14 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 274 ms 15348 KB Output is correct
2 Correct 264 ms 15172 KB Output is correct
3 Correct 257 ms 15012 KB Output is correct
4 Correct 251 ms 15800 KB Output is correct
5 Correct 277 ms 13604 KB Output is correct
6 Correct 730 ms 26204 KB Output is correct
7 Correct 297 ms 15556 KB Output is correct
8 Correct 347 ms 18348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 280 ms 14344 KB Output is correct
3 Correct 1281 ms 43408 KB Output is correct
4 Correct 1197 ms 43272 KB Output is correct
5 Correct 1089 ms 38668 KB Output is correct
6 Correct 503 ms 19388 KB Output is correct
7 Correct 150 ms 10480 KB Output is correct
8 Correct 30 ms 2560 KB Output is correct
9 Correct 1487 ms 42764 KB Output is correct
10 Correct 973 ms 38160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 915 ms 43132 KB Output is correct
2 Correct 872 ms 42240 KB Output is correct
3 Correct 402 ms 24456 KB Output is correct
4 Correct 881 ms 42556 KB Output is correct
5 Correct 925 ms 42892 KB Output is correct
6 Correct 312 ms 18552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 10 ms 768 KB Output is correct
20 Correct 9 ms 640 KB Output is correct
21 Correct 10 ms 768 KB Output is correct
22 Correct 17 ms 1024 KB Output is correct
23 Correct 14 ms 1024 KB Output is correct
24 Correct 15 ms 1024 KB Output is correct
25 Correct 14 ms 1024 KB Output is correct
26 Correct 14 ms 1024 KB Output is correct
27 Correct 14 ms 896 KB Output is correct
28 Correct 13 ms 1024 KB Output is correct
29 Correct 13 ms 1024 KB Output is correct
30 Correct 26 ms 1664 KB Output is correct
31 Correct 24 ms 1792 KB Output is correct
32 Correct 24 ms 1784 KB Output is correct
33 Correct 96 ms 6136 KB Output is correct
34 Correct 96 ms 6120 KB Output is correct
35 Correct 99 ms 6056 KB Output is correct
36 Correct 275 ms 14092 KB Output is correct
37 Correct 280 ms 14220 KB Output is correct
38 Correct 324 ms 14216 KB Output is correct
39 Correct 466 ms 11836 KB Output is correct
40 Correct 462 ms 11440 KB Output is correct
41 Correct 444 ms 11528 KB Output is correct
42 Correct 179 ms 13192 KB Output is correct
43 Correct 273 ms 13960 KB Output is correct
44 Correct 211 ms 14088 KB Output is correct
45 Correct 246 ms 14088 KB Output is correct
46 Correct 213 ms 13960 KB Output is correct
47 Correct 231 ms 14088 KB Output is correct
48 Correct 217 ms 14064 KB Output is correct
49 Correct 216 ms 13960 KB Output is correct
50 Correct 215 ms 13960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 10 ms 768 KB Output is correct
20 Correct 9 ms 640 KB Output is correct
21 Correct 10 ms 768 KB Output is correct
22 Correct 17 ms 1024 KB Output is correct
23 Correct 14 ms 1024 KB Output is correct
24 Correct 15 ms 1024 KB Output is correct
25 Correct 14 ms 1024 KB Output is correct
26 Correct 14 ms 1024 KB Output is correct
27 Correct 274 ms 15348 KB Output is correct
28 Correct 264 ms 15172 KB Output is correct
29 Correct 257 ms 15012 KB Output is correct
30 Correct 251 ms 15800 KB Output is correct
31 Correct 277 ms 13604 KB Output is correct
32 Correct 730 ms 26204 KB Output is correct
33 Correct 297 ms 15556 KB Output is correct
34 Correct 347 ms 18348 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 280 ms 14344 KB Output is correct
37 Correct 1281 ms 43408 KB Output is correct
38 Correct 1197 ms 43272 KB Output is correct
39 Correct 1089 ms 38668 KB Output is correct
40 Correct 503 ms 19388 KB Output is correct
41 Correct 150 ms 10480 KB Output is correct
42 Correct 30 ms 2560 KB Output is correct
43 Correct 1487 ms 42764 KB Output is correct
44 Correct 973 ms 38160 KB Output is correct
45 Correct 915 ms 43132 KB Output is correct
46 Correct 872 ms 42240 KB Output is correct
47 Correct 402 ms 24456 KB Output is correct
48 Correct 881 ms 42556 KB Output is correct
49 Correct 925 ms 42892 KB Output is correct
50 Correct 312 ms 18552 KB Output is correct
51 Correct 14 ms 896 KB Output is correct
52 Correct 13 ms 1024 KB Output is correct
53 Correct 13 ms 1024 KB Output is correct
54 Correct 26 ms 1664 KB Output is correct
55 Correct 24 ms 1792 KB Output is correct
56 Correct 24 ms 1784 KB Output is correct
57 Correct 96 ms 6136 KB Output is correct
58 Correct 96 ms 6120 KB Output is correct
59 Correct 99 ms 6056 KB Output is correct
60 Correct 275 ms 14092 KB Output is correct
61 Correct 280 ms 14220 KB Output is correct
62 Correct 324 ms 14216 KB Output is correct
63 Correct 466 ms 11836 KB Output is correct
64 Correct 462 ms 11440 KB Output is correct
65 Correct 444 ms 11528 KB Output is correct
66 Correct 179 ms 13192 KB Output is correct
67 Correct 273 ms 13960 KB Output is correct
68 Correct 211 ms 14088 KB Output is correct
69 Correct 246 ms 14088 KB Output is correct
70 Correct 213 ms 13960 KB Output is correct
71 Correct 231 ms 14088 KB Output is correct
72 Correct 217 ms 14064 KB Output is correct
73 Correct 216 ms 13960 KB Output is correct
74 Correct 215 ms 13960 KB Output is correct
75 Correct 293 ms 18008 KB Output is correct
76 Correct 285 ms 17428 KB Output is correct
77 Correct 285 ms 17356 KB Output is correct
78 Correct 287 ms 17292 KB Output is correct
79 Correct 318 ms 17112 KB Output is correct
80 Correct 276 ms 17224 KB Output is correct
81 Correct 1198 ms 43272 KB Output is correct
82 Correct 1173 ms 43016 KB Output is correct
83 Correct 1262 ms 43016 KB Output is correct
84 Correct 1086 ms 43532 KB Output is correct
85 Correct 1348 ms 43144 KB Output is correct
86 Correct 1092 ms 43144 KB Output is correct
87 Correct 1108 ms 43140 KB Output is correct
88 Correct 1549 ms 35184 KB Output is correct
89 Correct 1505 ms 35052 KB Output is correct
90 Correct 1437 ms 35104 KB Output is correct
91 Correct 1381 ms 35084 KB Output is correct
92 Correct 1406 ms 35012 KB Output is correct
93 Correct 1293 ms 42100 KB Output is correct
94 Correct 1209 ms 42636 KB Output is correct
95 Correct 1117 ms 42248 KB Output is correct
96 Correct 1081 ms 42124 KB Output is correct
97 Correct 1261 ms 42248 KB Output is correct
98 Correct 785 ms 32060 KB Output is correct
99 Correct 1286 ms 42212 KB Output is correct
100 Correct 1075 ms 42156 KB Output is correct
101 Correct 957 ms 37516 KB Output is correct
102 Correct 1077 ms 41864 KB Output is correct
103 Correct 1172 ms 41996 KB Output is correct
104 Correct 1204 ms 41996 KB Output is correct
105 Correct 779 ms 39816 KB Output is correct
106 Correct 745 ms 41352 KB Output is correct
107 Correct 788 ms 41456 KB Output is correct
108 Correct 837 ms 41532 KB Output is correct
109 Correct 831 ms 41492 KB Output is correct
110 Correct 719 ms 41352 KB Output is correct
111 Correct 797 ms 41480 KB Output is correct
112 Correct 784 ms 41480 KB Output is correct
113 Correct 752 ms 41480 KB Output is correct
114 Correct 714 ms 41352 KB Output is correct
115 Correct 716 ms 41356 KB Output is correct
116 Correct 740 ms 41352 KB Output is correct