Submission #373443

# Submission time Handle Problem Language Result Execution time Memory
373443 2021-03-04T15:41:02 Z LucaDantas Circle selection (APIO18_circle_selection) C++17
7 / 100
3000 ms 8284 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back

constexpr int maxn = 1e5+10, shift = 1000000001;

struct Circle
{
	int x, y, r, id;
	void db() {
		printf("(%d %d %d) ", x, y, r);
	}
} cc[maxn];

long long sq(int x) { return 1ll * x * x; }
bool intersect(Circle a, Circle b) {
	return sq(a.x - b.x) + sq(a.y - b.y) <= sq(a.r + b.r);
}

int B, n, ans[maxn];

vector<vector<Circle>> blocks;

void setBlocks() {
	sort(cc, cc+n, [](Circle a, Circle b) {
		if((a.x>>B) != (b.x>>B)) return a.x < b.x;
		return a.y < b.y;
	});
	vector<Circle> here = {cc[0]};
	for(int i = 1, last = cc[0].x; i < n; i++) {
		if((last>>B) == (cc[i].x>>B)) here.pb(cc[i]);
		else blocks.pb(here), here = {cc[i]};
		last = cc[i].x;
	}
	blocks.pb(here);
}

void doit(int i, int c) {
	int L = 0, R = (int)blocks[i].size()-1, best = -1, index = (cc[c].y>>B);
	while(L <= R) {
		int m = (L+R) >> 1;
		if((blocks[i][m].y>>B) >= index-2) best = m, R = m-1;
		else L = m+1;
	}
	for(; best < (int)blocks[i].size() && (blocks[i][best].y>>B) <= index+2; ++best) {
		if(intersect(cc[c], blocks[i][best]) && !ans[blocks[i][best].id])
			ans[blocks[i][best].id] = cc[c].id+1;
	}
}

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d %d %d", &cc[i].x, &cc[i].y, &cc[i].r);
		cc[i].x += shift; cc[i].y += shift;
		cc[i].id = i; B = max(B, cc[i].r);
	}
	B = 32 - __builtin_clz(B-1);
	setBlocks();

	sort(cc, cc+n, [](Circle a, Circle b) {
		if(a.r == b.r) return a.id < b.id;
		return a.r > b.r;
	});
	for(int i = 0; i < n; i++) {
		if(ans[cc[i].id]) continue;
		auto [x, y, r, id] = cc[i];
		// while((1 << B) >= (r << 1))
		// 	--B, rescale();

		int L = 0, R = (int)blocks.size()-1, best = -1, index = (x>>B);
		while(L <= R) {
			int m = (L+R) >> 1;
			if((blocks[m][0].x>>B) >= index-2) best = m, R = m-1;
			else L = m+1;
		}
		if(best == -1) continue;
		while(best < (int)blocks.size() && (blocks[best][0].x>>B) <= index+2)
			doit(best, i), ++best;
	}

	for(int i = 0; i < n; i++)
		printf("%d ", ans[i]);
	puts("");
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
circle_selection.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |   scanf("%d %d %d", &cc[i].x, &cc[i].y, &cc[i].r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 4 ms 816 KB Output is correct
20 Correct 4 ms 796 KB Output is correct
21 Correct 4 ms 796 KB Output is correct
22 Correct 5 ms 748 KB Output is correct
23 Correct 6 ms 620 KB Output is correct
24 Correct 5 ms 748 KB Output is correct
25 Correct 5 ms 876 KB Output is correct
26 Correct 5 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 41 ms 4204 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 119 ms 7404 KB Output is correct
3 Execution timed out 41 ms 4844 KB Time limit exceeded (wall clock)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 38 ms 2284 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 4 ms 816 KB Output is correct
20 Correct 4 ms 796 KB Output is correct
21 Correct 4 ms 796 KB Output is correct
22 Correct 5 ms 748 KB Output is correct
23 Correct 6 ms 620 KB Output is correct
24 Correct 5 ms 748 KB Output is correct
25 Correct 5 ms 876 KB Output is correct
26 Correct 5 ms 748 KB Output is correct
27 Correct 8 ms 1024 KB Output is correct
28 Correct 8 ms 1024 KB Output is correct
29 Correct 8 ms 1068 KB Output is correct
30 Correct 11 ms 1004 KB Output is correct
31 Correct 10 ms 1132 KB Output is correct
32 Correct 10 ms 1260 KB Output is correct
33 Correct 76 ms 8284 KB Output is correct
34 Correct 76 ms 8284 KB Output is correct
35 Correct 111 ms 7456 KB Output is correct
36 Correct 115 ms 7972 KB Output is correct
37 Correct 115 ms 8212 KB Output is correct
38 Correct 115 ms 7592 KB Output is correct
39 Execution timed out 3068 ms 6236 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 4 ms 816 KB Output is correct
20 Correct 4 ms 796 KB Output is correct
21 Correct 4 ms 796 KB Output is correct
22 Correct 5 ms 748 KB Output is correct
23 Correct 6 ms 620 KB Output is correct
24 Correct 5 ms 748 KB Output is correct
25 Correct 5 ms 876 KB Output is correct
26 Correct 5 ms 748 KB Output is correct
27 Execution timed out 41 ms 4204 KB Time limit exceeded (wall clock)
28 Halted 0 ms 0 KB -