답안 #49275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49275 2018-05-24T17:49:14 Z zadrga 원 고르기 (APIO18_circle_selection) C++14
87 / 100
3000 ms 24156 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 300111

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

struct circle{
	ll x, y, r;
	int ind;
} c[maxn], a[maxn];

bool used[maxn];
int ans[maxn], order[maxn];
int n, cur_r, next_r;

bool operator<(circle a, circle b){
	if(a.x == b.x)	
		return a.y < b.y;

	return a.x < b.x;
}

bool comp(int x, int y){
	if(a[x].r == a[y].r)
		return a[x].ind < a[y].ind;

	return a[x].r > a[y].r;
}

void rescale(){
	cur_r = next_r;
	next_r = cur_r / 2;

	for(int i = 1; i <= n; i++){
		int cur = c[i].ind;
		c[i].x = a[cur].x / cur_r;
		c[i].y = a[cur].y / cur_r;
	}

	sort(c + 1, c + 1 + n);
}

bool intersection(circle &a, circle &b){
	ll dist_center = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
	ll dist_r = (a.r + b.r) * (a.r + b.r);
	return dist_center <= dist_r;
}

void solve(int cur){
	int pos_x = a[cur].x / cur_r;
	int pos_y = a[cur].y / cur_r;

	ans[cur] = cur;
	used[cur] = 1;

//	cout << cur << "  " << a[cur].x << "  " << a[cur].y << "  "<< a[cur].r << ":  " << endl;

	for(int cur_x = pos_x - 2; cur_x <= pos_x + 2; cur_x++){
		int it = lower_bound(c + 1, c + 1 + n, (circle) {cur_x, pos_y - 2, -1, -1}) - c;
		while(it <= n && c[it].x == cur_x && c[it].y <= pos_y + 2){
	//		cout << c[it].ind << "  " << a[c[it].ind].x << "  " << a[c[it].ind].y << "  " << a[c[it].ind].r << endl;
			if(!used[c[it].ind] && intersection(a[c[it].ind], a[cur])){
				ans[c[it].ind] = cur;
				used[c[it].ind] = 1;
			}
			it++;
		}
	}

	//cout << endl << endl;
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		ll x, y, r;
		scanf("%lld%lld%lld", &x, &y, &r);
		a[i] = c[i] = {x, y, r, i};
		order[i] = i;
	}

	sort(c + 1, c + 1 + n);
	sort(order + 1, order + 1 + n, comp);

	next_r = a[order[1]].r; 
	rescale();

	for(int i = 1; i <= n; i++){
		if(used[order[i]])
			continue;

		if(a[order[i]].r <= next_r)
			rescale();

		solve(order[i]);
	}

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

	return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:84:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
circle_selection.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &x, &y, &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 4 ms 636 KB Output is correct
18 Correct 4 ms 636 KB Output is correct
19 Correct 9 ms 1020 KB Output is correct
20 Correct 10 ms 1020 KB Output is correct
21 Correct 8 ms 1036 KB Output is correct
22 Correct 12 ms 1052 KB Output is correct
23 Correct 17 ms 1068 KB Output is correct
24 Correct 14 ms 1068 KB Output is correct
25 Correct 13 ms 1068 KB Output is correct
26 Correct 14 ms 1068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 460 ms 24148 KB Output is correct
2 Correct 476 ms 24148 KB Output is correct
3 Correct 393 ms 24148 KB Output is correct
4 Correct 495 ms 24148 KB Output is correct
5 Correct 660 ms 24148 KB Output is correct
6 Correct 916 ms 24148 KB Output is correct
7 Correct 791 ms 24148 KB Output is correct
8 Correct 771 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 24148 KB Output is correct
2 Correct 537 ms 24148 KB Output is correct
3 Correct 1928 ms 24148 KB Output is correct
4 Correct 1984 ms 24148 KB Output is correct
5 Correct 2000 ms 24148 KB Output is correct
6 Correct 581 ms 24148 KB Output is correct
7 Correct 240 ms 24148 KB Output is correct
8 Correct 37 ms 24148 KB Output is correct
9 Correct 1948 ms 24148 KB Output is correct
10 Correct 1173 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 760 ms 24148 KB Output is correct
2 Correct 621 ms 24148 KB Output is correct
3 Correct 414 ms 24148 KB Output is correct
4 Correct 653 ms 24148 KB Output is correct
5 Correct 638 ms 24148 KB Output is correct
6 Correct 384 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 4 ms 636 KB Output is correct
18 Correct 4 ms 636 KB Output is correct
19 Correct 9 ms 1020 KB Output is correct
20 Correct 10 ms 1020 KB Output is correct
21 Correct 8 ms 1036 KB Output is correct
22 Correct 12 ms 1052 KB Output is correct
23 Correct 17 ms 1068 KB Output is correct
24 Correct 14 ms 1068 KB Output is correct
25 Correct 13 ms 1068 KB Output is correct
26 Correct 14 ms 1068 KB Output is correct
27 Correct 19 ms 24148 KB Output is correct
28 Correct 13 ms 24148 KB Output is correct
29 Correct 12 ms 24148 KB Output is correct
30 Correct 31 ms 24148 KB Output is correct
31 Correct 27 ms 24148 KB Output is correct
32 Correct 29 ms 24148 KB Output is correct
33 Correct 131 ms 24148 KB Output is correct
34 Correct 124 ms 24148 KB Output is correct
35 Correct 417 ms 24148 KB Output is correct
36 Correct 476 ms 24148 KB Output is correct
37 Correct 502 ms 24148 KB Output is correct
38 Correct 494 ms 24148 KB Output is correct
39 Correct 896 ms 24148 KB Output is correct
40 Correct 811 ms 24148 KB Output is correct
41 Correct 845 ms 24148 KB Output is correct
42 Correct 135 ms 24148 KB Output is correct
43 Correct 186 ms 24148 KB Output is correct
44 Correct 239 ms 24148 KB Output is correct
45 Correct 183 ms 24148 KB Output is correct
46 Correct 191 ms 24148 KB Output is correct
47 Correct 194 ms 24148 KB Output is correct
48 Correct 222 ms 24148 KB Output is correct
49 Correct 151 ms 24148 KB Output is correct
50 Correct 157 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 4 ms 636 KB Output is correct
18 Correct 4 ms 636 KB Output is correct
19 Correct 9 ms 1020 KB Output is correct
20 Correct 10 ms 1020 KB Output is correct
21 Correct 8 ms 1036 KB Output is correct
22 Correct 12 ms 1052 KB Output is correct
23 Correct 17 ms 1068 KB Output is correct
24 Correct 14 ms 1068 KB Output is correct
25 Correct 13 ms 1068 KB Output is correct
26 Correct 14 ms 1068 KB Output is correct
27 Correct 460 ms 24148 KB Output is correct
28 Correct 476 ms 24148 KB Output is correct
29 Correct 393 ms 24148 KB Output is correct
30 Correct 495 ms 24148 KB Output is correct
31 Correct 660 ms 24148 KB Output is correct
32 Correct 916 ms 24148 KB Output is correct
33 Correct 791 ms 24148 KB Output is correct
34 Correct 771 ms 24148 KB Output is correct
35 Correct 3 ms 24148 KB Output is correct
36 Correct 537 ms 24148 KB Output is correct
37 Correct 1928 ms 24148 KB Output is correct
38 Correct 1984 ms 24148 KB Output is correct
39 Correct 2000 ms 24148 KB Output is correct
40 Correct 581 ms 24148 KB Output is correct
41 Correct 240 ms 24148 KB Output is correct
42 Correct 37 ms 24148 KB Output is correct
43 Correct 1948 ms 24148 KB Output is correct
44 Correct 1173 ms 24148 KB Output is correct
45 Correct 760 ms 24148 KB Output is correct
46 Correct 621 ms 24148 KB Output is correct
47 Correct 414 ms 24148 KB Output is correct
48 Correct 653 ms 24148 KB Output is correct
49 Correct 638 ms 24148 KB Output is correct
50 Correct 384 ms 24148 KB Output is correct
51 Correct 19 ms 24148 KB Output is correct
52 Correct 13 ms 24148 KB Output is correct
53 Correct 12 ms 24148 KB Output is correct
54 Correct 31 ms 24148 KB Output is correct
55 Correct 27 ms 24148 KB Output is correct
56 Correct 29 ms 24148 KB Output is correct
57 Correct 131 ms 24148 KB Output is correct
58 Correct 124 ms 24148 KB Output is correct
59 Correct 417 ms 24148 KB Output is correct
60 Correct 476 ms 24148 KB Output is correct
61 Correct 502 ms 24148 KB Output is correct
62 Correct 494 ms 24148 KB Output is correct
63 Correct 896 ms 24148 KB Output is correct
64 Correct 811 ms 24148 KB Output is correct
65 Correct 845 ms 24148 KB Output is correct
66 Correct 135 ms 24148 KB Output is correct
67 Correct 186 ms 24148 KB Output is correct
68 Correct 239 ms 24148 KB Output is correct
69 Correct 183 ms 24148 KB Output is correct
70 Correct 191 ms 24148 KB Output is correct
71 Correct 194 ms 24148 KB Output is correct
72 Correct 222 ms 24148 KB Output is correct
73 Correct 151 ms 24148 KB Output is correct
74 Correct 157 ms 24148 KB Output is correct
75 Correct 1353 ms 24148 KB Output is correct
76 Correct 546 ms 24156 KB Output is correct
77 Correct 414 ms 24156 KB Output is correct
78 Correct 443 ms 24156 KB Output is correct
79 Correct 1532 ms 24156 KB Output is correct
80 Correct 442 ms 24156 KB Output is correct
81 Correct 1756 ms 24156 KB Output is correct
82 Correct 1588 ms 24156 KB Output is correct
83 Correct 1593 ms 24156 KB Output is correct
84 Correct 1654 ms 24156 KB Output is correct
85 Correct 1670 ms 24156 KB Output is correct
86 Correct 1696 ms 24156 KB Output is correct
87 Correct 1940 ms 24156 KB Output is correct
88 Correct 2807 ms 24156 KB Output is correct
89 Execution timed out 3046 ms 24156 KB Time limit exceeded
90 Halted 0 ms 0 KB -