답안 #243421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
243421 2020-07-01T05:06:37 Z atoiz 원 고르기 (APIO18_circle_selection) C++14
49 / 100
3000 ms 195776 KB
/*input
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
*/

// spoiled

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <unordered_map>

using namespace std;

inline long long sqr(int x) { return (long long) x * x; }

struct Circle
{
	int x, y, r, i;
	bool intersect(const Circle &c) const
	{
		return sqr(c.x - x) + sqr(c.y - y) <= sqr(r + c.r);
	}
};

const int OFFSET = 1000 * 1000 * 1000;
int N;
vector<Circle> cir;
vector<int> ans;
unordered_map<int, unordered_map<int, vector<int>>> grid;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	ans.assign(N, -1);
	cir.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> cir[i].x >> cir[i].y >> cir[i].r;
		cir[i].x += OFFSET;
		cir[i].y += OFFSET;
		cir[i].i = i;
	}

	auto vec = cir;
	sort(vec.begin(), vec.end(), [&](Circle &a, Circle &b) {
		return (a.r == b.r ? (a.i < b.i) : (a.r > b.r));
	});

	auto c = vec.begin();
	for (int i = 30; i >= 0; --i) {
		grid.clear();
		for (auto t : vec) if (!~ans[t.i]) {
			grid[t.x >> i][t.y >> i].push_back(t.i);
		}

		for (; c != vec.end() && c->r > ((1 << i) >> 1); ++c) if (!~ans[c->i]) {
			int cx = c->x >> i, cy = c->y >> i;
			for (int tx = cx - 2; tx <= cx + 2; ++tx) {
				for (int ty = cy - 2; ty <= cy + 2; ++ty) {
					vector<int> &cur = grid[tx][ty], tmp;
					if (cur.empty()) continue;
					for (int id : cur) {
						if (c->intersect(cir[id])) {
							ans[id] = c->i;
						} else {
							tmp.push_back(id);
						}
					}
					cur = move(tmp);
				}
			}
		}
	}

	for (int i = 0; i < N; ++i) cout << ans[i] + 1 << ' ';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 8 ms 800 KB Output is correct
20 Correct 8 ms 768 KB Output is correct
21 Correct 8 ms 768 KB Output is correct
22 Correct 39 ms 4480 KB Output is correct
23 Correct 38 ms 4224 KB Output is correct
24 Correct 40 ms 3992 KB Output is correct
25 Correct 46 ms 5112 KB Output is correct
26 Correct 51 ms 4856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 19908 KB Output is correct
2 Correct 226 ms 20252 KB Output is correct
3 Correct 226 ms 21700 KB Output is correct
4 Correct 204 ms 19912 KB Output is correct
5 Correct 482 ms 20372 KB Output is correct
6 Correct 1755 ms 69592 KB Output is correct
7 Correct 528 ms 22352 KB Output is correct
8 Correct 763 ms 32180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 1486 ms 70660 KB Output is correct
3 Execution timed out 3102 ms 195776 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3096 ms 172132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 8 ms 800 KB Output is correct
20 Correct 8 ms 768 KB Output is correct
21 Correct 8 ms 768 KB Output is correct
22 Correct 39 ms 4480 KB Output is correct
23 Correct 38 ms 4224 KB Output is correct
24 Correct 40 ms 3992 KB Output is correct
25 Correct 46 ms 5112 KB Output is correct
26 Correct 51 ms 4856 KB Output is correct
27 Correct 12 ms 1152 KB Output is correct
28 Correct 12 ms 1152 KB Output is correct
29 Correct 12 ms 1184 KB Output is correct
30 Correct 83 ms 8904 KB Output is correct
31 Correct 93 ms 9592 KB Output is correct
32 Correct 91 ms 7420 KB Output is correct
33 Correct 84 ms 7672 KB Output is correct
34 Correct 78 ms 7660 KB Output is correct
35 Correct 86 ms 8144 KB Output is correct
36 Correct 1597 ms 82656 KB Output is correct
37 Correct 1680 ms 74004 KB Output is correct
38 Correct 1775 ms 80912 KB Output is correct
39 Correct 607 ms 25860 KB Output is correct
40 Correct 511 ms 25980 KB Output is correct
41 Correct 514 ms 25880 KB Output is correct
42 Correct 263 ms 11700 KB Output is correct
43 Correct 1315 ms 176168 KB Output is correct
44 Correct 1313 ms 176336 KB Output is correct
45 Correct 1361 ms 175984 KB Output is correct
46 Correct 1309 ms 176336 KB Output is correct
47 Correct 1507 ms 176424 KB Output is correct
48 Correct 1299 ms 176544 KB Output is correct
49 Correct 1489 ms 176460 KB Output is correct
50 Correct 1287 ms 176248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 8 ms 800 KB Output is correct
20 Correct 8 ms 768 KB Output is correct
21 Correct 8 ms 768 KB Output is correct
22 Correct 39 ms 4480 KB Output is correct
23 Correct 38 ms 4224 KB Output is correct
24 Correct 40 ms 3992 KB Output is correct
25 Correct 46 ms 5112 KB Output is correct
26 Correct 51 ms 4856 KB Output is correct
27 Correct 230 ms 19908 KB Output is correct
28 Correct 226 ms 20252 KB Output is correct
29 Correct 226 ms 21700 KB Output is correct
30 Correct 204 ms 19912 KB Output is correct
31 Correct 482 ms 20372 KB Output is correct
32 Correct 1755 ms 69592 KB Output is correct
33 Correct 528 ms 22352 KB Output is correct
34 Correct 763 ms 32180 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 1486 ms 70660 KB Output is correct
37 Execution timed out 3102 ms 195776 KB Time limit exceeded
38 Halted 0 ms 0 KB -