Submission #49274

# Submission time Handle Problem Language Result Execution time Memory
49274 2018-05-24T17:47:20 Z zadrga Circle selection (APIO18_circle_selection) C++14
12 / 100
728 ms 24204 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;
	}
}

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:82:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
circle_selection.cpp:85: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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 516 KB Output is correct
7 Correct 2 ms 516 KB Output is correct
8 Correct 2 ms 516 KB Output is correct
9 Incorrect 3 ms 544 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 439 ms 24032 KB Output is correct
2 Correct 407 ms 24052 KB Output is correct
3 Correct 423 ms 24052 KB Output is correct
4 Correct 398 ms 24204 KB Output is correct
5 Correct 602 ms 24204 KB Output is correct
6 Correct 667 ms 24204 KB Output is correct
7 Correct 608 ms 24204 KB Output is correct
8 Correct 728 ms 24204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 24204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 713 ms 24204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 516 KB Output is correct
7 Correct 2 ms 516 KB Output is correct
8 Correct 2 ms 516 KB Output is correct
9 Incorrect 3 ms 544 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 516 KB Output is correct
7 Correct 2 ms 516 KB Output is correct
8 Correct 2 ms 516 KB Output is correct
9 Incorrect 3 ms 544 KB Output isn't correct
10 Halted 0 ms 0 KB -