Submission #453758

# Submission time Handle Problem Language Result Execution time Memory
453758 2021-08-04T17:07:42 Z arminatarod Circle selection (APIO18_circle_selection) C++17
0 / 100
3000 ms 621124 KB
#include <bits/stdc++.h>
 
using namespace std;
 
constexpr int MAXN = 300005;
 
constexpr int MAXINT = 1073741823;
 
vector<int> all_numbers;
 
vector<int> neighbors[MAXN];
 
struct circles {
	long long int x, y, radius;
} circle[MAXN];
 
int sorted[MAXN], answer[MAXN];
 
int the_radius;
 
bitset<MAXN> deleted;
 
bool comparison(int x, int y) {
	return (circle[x].radius == circle[y].radius? x < y : circle[x].radius > circle[y].radius);
}
 
bool check(circles u, circles v) {
	long long int distance_2 = (u.x - v.x) * (u.x - v.x) + (u.y - v.y) * (u.y - v.y);
	long long int radius_2 = (u.radius + v.radius) * (u.radius + v.radius);
	return (radius_2 >= distance_2);
}
 
map<pair<int, int>, set<int>> circles_of;
 
pair<int, int> get_cell(int x, int y) {
	pair<int, int> result;
	result.first = (x >= 0? x / the_radius : (x - the_radius + 1) / the_radius);
	result.second = (y >= 0? y / the_radius : (y - the_radius + 1) / the_radius);
	return result;
}

vector<int> to_delete;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long int n, distance_2, radius_2;
	pair<int, int> center_cell;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> circle[i].x >> circle[i].y >> circle[i].radius;
		the_radius = circle[i].radius;
		circles_of[get_cell(circle[i].x, circle[i].y)].insert(i);
		sorted[i] = i;
	}
	sort(sorted, sorted + n, comparison);
	for (int i = 0; i < n; i++)
		if (!deleted[sorted[i]]) {
			center_cell = get_cell(circle[sorted[i]].x, circle[sorted[i]].y);
			for (int x = center_cell.first - 2; x <= center_cell.first + 2; x++)
				for (int y = center_cell.second - 2; y <= center_cell.second + 2; y++) {
					to_delete.clear();
					for (int j : circles_of[make_pair(x, y)])
						if (check(circle[j], circle[sorted[i]])) {
							answer[j] = sorted[i];
							deleted[j] = true;
							to_delete.push_back(j);
						}
					for (int j : to_delete)
						circles_of[make_pair(x, y)].erase(j);
				}
		}
	for (int i = 0; i < n; i++)
		cout << answer[i] + 1 << ' ';
	return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:47:19: warning: unused variable 'distance_2' [-Wunused-variable]
   47 |  long long int n, distance_2, radius_2;
      |                   ^~~~~~~~~~
circle_selection.cpp:47:31: warning: unused variable 'radius_2' [-Wunused-variable]
   47 |  long long int n, distance_2, radius_2;
      |                               ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7368 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Incorrect 4 ms 7372 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 369 ms 33364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 7372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3098 ms 621124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7368 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Incorrect 4 ms 7372 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7368 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Incorrect 4 ms 7372 KB Output isn't correct
4 Halted 0 ms 0 KB -