Submission #111248

# Submission time Handle Problem Language Result Execution time Memory
111248 2019-05-14T13:23:08 Z Just_Solve_The_Problem Circle selection (APIO18_circle_selection) C++17
72 / 100
3000 ms 55376 KB
#include <set>
#include <map>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <numeric>
#pragma GCC optimize("Ofast")
 
#define ll long long
 
using namespace std;
 
const int N = (int)3e5 + 7;
 
int x[N], y[N], r[N];
int n;
int ans[N];
map<pair<int, int>, vector<int>> mp;
int pos[N];
int block = 0;
set <int> ost;

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

ll dist(int x1, int y1, int x2, int y2) {
	return sqr(x1 - x2) + sqr(y1 - y2);
}

void rescale() {
	mp.clear();
	for (int to : ost) {
		mp[{x[to] / block, y[to] / block}].push_back(to);
	}
}

main() {
	iota(pos, pos + N, 0);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d %d", &x[i], &y[i], &r[i]);
		ost.insert(i);
	}
	sort(pos + 1, pos + n + 1, [&](const int &A, const int &B) {
		if (r[A] == r[B]) return A < B;
		return r[A] > r[B];
	});
	for (int i = 1; i <= n; i++) {
		if (ans[pos[i]]) continue;
		if (block == 0 || r[pos[i]] * 2 <= block) {
			block = r[pos[i]];
			rescale();
		}
		for (int cx = x[pos[i]] / block - 2; cx <= x[pos[i]] / block + 2; cx++) {
			for (int cy = y[pos[i]] / block - 2; cy <= y[pos[i]] / block + 2; cy++) {
				if (!mp.count({cx, cy})) continue;
				for (int to : mp[{cx, cy}]) {
					if (!ans[to] && dist(x[pos[i]], y[pos[i]], x[to], y[to]) <= sqr(r[pos[i]] + r[to])) {
						ans[to] = pos[i];
						ost.erase(to);
					}
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		printf("%d ", ans[i]);
	}
}
/*
11
9 9 3
13 2 3
11 8 3
3 3 3
3 12 3
12 14 3
9 8 3
2 8 3
5 2 3
14 4 3
14 14 3
*/

Compilation message

circle_selection.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
circle_selection.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &x[i], &y[i], &r[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 4 ms 1536 KB Output is correct
3 Correct 3 ms 1536 KB Output is correct
4 Correct 3 ms 1536 KB Output is correct
5 Correct 3 ms 1536 KB Output is correct
6 Correct 3 ms 1536 KB Output is correct
7 Correct 3 ms 1536 KB Output is correct
8 Correct 3 ms 1536 KB Output is correct
9 Correct 3 ms 1536 KB Output is correct
10 Correct 3 ms 1536 KB Output is correct
11 Correct 3 ms 1452 KB Output is correct
12 Correct 3 ms 1536 KB Output is correct
13 Correct 3 ms 1536 KB Output is correct
14 Correct 3 ms 1536 KB Output is correct
15 Correct 4 ms 1664 KB Output is correct
16 Correct 4 ms 1536 KB Output is correct
17 Correct 4 ms 1620 KB Output is correct
18 Correct 5 ms 1536 KB Output is correct
19 Correct 6 ms 1920 KB Output is correct
20 Correct 6 ms 1920 KB Output is correct
21 Correct 8 ms 2048 KB Output is correct
22 Correct 24 ms 2444 KB Output is correct
23 Correct 27 ms 2432 KB Output is correct
24 Correct 22 ms 2432 KB Output is correct
25 Correct 17 ms 2304 KB Output is correct
26 Correct 26 ms 2432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 347 ms 22464 KB Output is correct
2 Correct 391 ms 23328 KB Output is correct
3 Correct 400 ms 23612 KB Output is correct
4 Correct 353 ms 22388 KB Output is correct
5 Correct 799 ms 23004 KB Output is correct
6 Correct 1768 ms 38540 KB Output is correct
7 Correct 961 ms 24496 KB Output is correct
8 Correct 1081 ms 28512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 865 ms 19404 KB Output is correct
3 Execution timed out 3031 ms 53304 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2274 ms 55332 KB Output is correct
2 Correct 1567 ms 55304 KB Output is correct
3 Correct 1158 ms 32036 KB Output is correct
4 Correct 1738 ms 55248 KB Output is correct
5 Correct 1811 ms 55376 KB Output is correct
6 Correct 878 ms 25684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 4 ms 1536 KB Output is correct
3 Correct 3 ms 1536 KB Output is correct
4 Correct 3 ms 1536 KB Output is correct
5 Correct 3 ms 1536 KB Output is correct
6 Correct 3 ms 1536 KB Output is correct
7 Correct 3 ms 1536 KB Output is correct
8 Correct 3 ms 1536 KB Output is correct
9 Correct 3 ms 1536 KB Output is correct
10 Correct 3 ms 1536 KB Output is correct
11 Correct 3 ms 1452 KB Output is correct
12 Correct 3 ms 1536 KB Output is correct
13 Correct 3 ms 1536 KB Output is correct
14 Correct 3 ms 1536 KB Output is correct
15 Correct 4 ms 1664 KB Output is correct
16 Correct 4 ms 1536 KB Output is correct
17 Correct 4 ms 1620 KB Output is correct
18 Correct 5 ms 1536 KB Output is correct
19 Correct 6 ms 1920 KB Output is correct
20 Correct 6 ms 1920 KB Output is correct
21 Correct 8 ms 2048 KB Output is correct
22 Correct 24 ms 2444 KB Output is correct
23 Correct 27 ms 2432 KB Output is correct
24 Correct 22 ms 2432 KB Output is correct
25 Correct 17 ms 2304 KB Output is correct
26 Correct 26 ms 2432 KB Output is correct
27 Correct 16 ms 2176 KB Output is correct
28 Correct 11 ms 2304 KB Output is correct
29 Correct 12 ms 2304 KB Output is correct
30 Correct 118 ms 3320 KB Output is correct
31 Correct 50 ms 3200 KB Output is correct
32 Correct 40 ms 3320 KB Output is correct
33 Correct 109 ms 8948 KB Output is correct
34 Correct 109 ms 8944 KB Output is correct
35 Correct 136 ms 8588 KB Output is correct
36 Correct 785 ms 19420 KB Output is correct
37 Correct 774 ms 19348 KB Output is correct
38 Correct 873 ms 19268 KB Output is correct
39 Correct 719 ms 17776 KB Output is correct
40 Correct 679 ms 17696 KB Output is correct
41 Correct 587 ms 17728 KB Output is correct
42 Correct 569 ms 19480 KB Output is correct
43 Correct 435 ms 19108 KB Output is correct
44 Correct 432 ms 19192 KB Output is correct
45 Correct 426 ms 19064 KB Output is correct
46 Correct 513 ms 19112 KB Output is correct
47 Correct 503 ms 19064 KB Output is correct
48 Correct 480 ms 19160 KB Output is correct
49 Correct 488 ms 19192 KB Output is correct
50 Correct 482 ms 19092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 4 ms 1536 KB Output is correct
3 Correct 3 ms 1536 KB Output is correct
4 Correct 3 ms 1536 KB Output is correct
5 Correct 3 ms 1536 KB Output is correct
6 Correct 3 ms 1536 KB Output is correct
7 Correct 3 ms 1536 KB Output is correct
8 Correct 3 ms 1536 KB Output is correct
9 Correct 3 ms 1536 KB Output is correct
10 Correct 3 ms 1536 KB Output is correct
11 Correct 3 ms 1452 KB Output is correct
12 Correct 3 ms 1536 KB Output is correct
13 Correct 3 ms 1536 KB Output is correct
14 Correct 3 ms 1536 KB Output is correct
15 Correct 4 ms 1664 KB Output is correct
16 Correct 4 ms 1536 KB Output is correct
17 Correct 4 ms 1620 KB Output is correct
18 Correct 5 ms 1536 KB Output is correct
19 Correct 6 ms 1920 KB Output is correct
20 Correct 6 ms 1920 KB Output is correct
21 Correct 8 ms 2048 KB Output is correct
22 Correct 24 ms 2444 KB Output is correct
23 Correct 27 ms 2432 KB Output is correct
24 Correct 22 ms 2432 KB Output is correct
25 Correct 17 ms 2304 KB Output is correct
26 Correct 26 ms 2432 KB Output is correct
27 Correct 347 ms 22464 KB Output is correct
28 Correct 391 ms 23328 KB Output is correct
29 Correct 400 ms 23612 KB Output is correct
30 Correct 353 ms 22388 KB Output is correct
31 Correct 799 ms 23004 KB Output is correct
32 Correct 1768 ms 38540 KB Output is correct
33 Correct 961 ms 24496 KB Output is correct
34 Correct 1081 ms 28512 KB Output is correct
35 Correct 3 ms 1536 KB Output is correct
36 Correct 865 ms 19404 KB Output is correct
37 Execution timed out 3031 ms 53304 KB Time limit exceeded
38 Halted 0 ms 0 KB -