답안 #1033495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033495 2024-07-24T23:15:02 Z crimson231 원 고르기 (APIO18_circle_selection) C++17
100 / 100
566 ms 49700 KB
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <vector>
#include <unordered_map>
typedef long long ll;
typedef double ld;
typedef std::vector<int> Vint;
#define radius x
#define idx y
const int LEN = 3e5 + 5;
inline ll sq(const ll& x) { return x * x; }

int N;
int V[LEN];
struct Pos {
	ll x, y;
	Pos(ll X = 0, ll Y = 0) : x(X), y(Y) {}
	Pos operator + (const Pos& p) const { return { x + p.x, y + p.y }; }
	Pos operator - (const Pos& p) const { return { x - p.x, y - p.y }; }
	Pos operator * (const int& n) const { return { x * n, y * n }; }
	Pos operator / (const int& n) const { return { x / n, y / n }; }
	Pos operator ^ (const Pos& p) const { return { x * p.x, y * p.y }; }
	Pos& operator += (const Pos& p) { x += p.x; y += p.y; return *this; }
	ll Euc() const { return (ll)x * x + (ll)y * y; }
	friend std::istream& operator >> (std::istream& is, Pos& p) { is >> p.x >> p.y; return is; }
	friend std::ostream& operator << (std::ostream& os, const Pos& p) { os << p.x << " " << p.y; return os; }
};
typedef std::vector<Pos> Polygon;
struct Circle {
	Pos c;
	ll r;
	Circle(Pos C = Pos(0, 0), ll R = 0) : c(C), r(R) {}
	bool meet(const Circle& q) const { return sq(r + q.r) >= (c - q.c).Euc(); }
	friend std::istream& operator >> (std::istream& is, Circle& c) { is >> c.c >> c.r; return is; }
	friend std::ostream& operator << (std::ostream& os, const Circle& c) { os << c.c << " " << c.r; return os; }
};
bool cmpri(const Pos& p, const Pos& q) { return p.radius == q.radius ? p.idx < q.idx : p.radius > q.radius; }
typedef std::vector<Circle> Disks;
typedef std::unordered_map<ll, Vint> Table;
Table idxs;
ll key(const Pos& p, const int& ex) { return ((p.x / (1ll << ex)) << 32) | (p.y / (1ll << ex)); }
void grid_init(Table& T, const Disks& C, const int& ex) {
	T.clear();
	int sz = C.size();
	for (int i = 0; i < sz; i++) {
		if (V[i]) continue;
		const Pos& p = C[i].c;
		T[key(p, ex)].push_back(i);
	}
	return;
}
void solve() {
	std::cin.tie(0)->sync_with_stdio(0);
	std::cout.tie(0);
	std::cout << std::fixed;
	std::cout.precision(15);
	std::cin >> N;
	Polygon R(N);
	Disks C(N);
	Pos w = Pos(1ll << 30, 1ll << 30);
	for (int i = 0; i < N; i++) {
		std::cin >> C[i];
		C[i].c += w;
		R[i] = Pos(C[i].r, i);
	}
	std::sort(R.begin(), R.end(), cmpri);
	memset(V, 0, sizeof V);
	int ex = 30;//exponent of the interval dividing the grid
	while ((1ll << ex) >= (R[0].radius) * 2) ex--;
	grid_init(idxs, C, ex);
	for (int i = 0; i < N; i++) {
		if (V[R[i].idx]) continue;
		if ((1ll << ex) >= (R[i].radius) * 2) {
			while ((1ll << ex) >= (R[i].radius) * 2) ex--;
			grid_init(idxs, C, ex);
		}
		int I = R[i].idx;
		Pos p = C[I].c;
		for (int x = -2; x <= 2; x++) {
			for (int y = -2; y <= 2; y++) {
				ll dx = (1ll << ex) * x, dy = (1ll << ex) * y;
				ll K = key(p + Pos(dx, dy), ex);
				if (!idxs.count(K)) continue;
				const Vint& vi = idxs[K];
				for (const int& v : vi) {
					if (V[v]) continue;
					if (C[I].meet(C[v])) V[v] = I + 1;
				}
			}
		}
	}
	for (int i = 0; i < N; i++) std::cout << V[i] << " ";
	return;
}
int main() { solve(); return 0; }//APIO 2018 B boj15767 Circle selection
//refer to jjang36524
//https://jjang36524.tistory.com/26
//https://codeforces.com/blog/entry/59650
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1624 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 0 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 0 ms 1628 KB Output is correct
11 Correct 1 ms 1628 KB Output is correct
12 Correct 1 ms 1624 KB Output is correct
13 Correct 1 ms 1628 KB Output is correct
14 Correct 1 ms 1628 KB Output is correct
15 Correct 1 ms 1628 KB Output is correct
16 Correct 1 ms 1560 KB Output is correct
17 Correct 1 ms 1628 KB Output is correct
18 Correct 1 ms 1628 KB Output is correct
19 Correct 2 ms 1884 KB Output is correct
20 Correct 2 ms 1836 KB Output is correct
21 Correct 3 ms 1884 KB Output is correct
22 Correct 5 ms 2396 KB Output is correct
23 Correct 5 ms 2392 KB Output is correct
24 Correct 6 ms 2392 KB Output is correct
25 Correct 6 ms 2392 KB Output is correct
26 Correct 8 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 22312 KB Output is correct
2 Correct 94 ms 22224 KB Output is correct
3 Correct 97 ms 23492 KB Output is correct
4 Correct 108 ms 22320 KB Output is correct
5 Correct 101 ms 22096 KB Output is correct
6 Correct 184 ms 30352 KB Output is correct
7 Correct 129 ms 23124 KB Output is correct
8 Correct 136 ms 24748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 114 ms 17920 KB Output is correct
3 Correct 430 ms 49532 KB Output is correct
4 Correct 516 ms 49532 KB Output is correct
5 Correct 414 ms 45436 KB Output is correct
6 Correct 185 ms 23752 KB Output is correct
7 Correct 86 ms 13004 KB Output is correct
8 Correct 15 ms 3932 KB Output is correct
9 Correct 566 ms 48832 KB Output is correct
10 Correct 397 ms 43668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 485 ms 49472 KB Output is correct
2 Correct 529 ms 48504 KB Output is correct
3 Correct 152 ms 30048 KB Output is correct
4 Correct 462 ms 49020 KB Output is correct
5 Correct 462 ms 49024 KB Output is correct
6 Correct 114 ms 26196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1624 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 0 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 0 ms 1628 KB Output is correct
11 Correct 1 ms 1628 KB Output is correct
12 Correct 1 ms 1624 KB Output is correct
13 Correct 1 ms 1628 KB Output is correct
14 Correct 1 ms 1628 KB Output is correct
15 Correct 1 ms 1628 KB Output is correct
16 Correct 1 ms 1560 KB Output is correct
17 Correct 1 ms 1628 KB Output is correct
18 Correct 1 ms 1628 KB Output is correct
19 Correct 2 ms 1884 KB Output is correct
20 Correct 2 ms 1836 KB Output is correct
21 Correct 3 ms 1884 KB Output is correct
22 Correct 5 ms 2396 KB Output is correct
23 Correct 5 ms 2392 KB Output is correct
24 Correct 6 ms 2392 KB Output is correct
25 Correct 6 ms 2392 KB Output is correct
26 Correct 8 ms 2396 KB Output is correct
27 Correct 4 ms 2396 KB Output is correct
28 Correct 4 ms 2456 KB Output is correct
29 Correct 3 ms 2396 KB Output is correct
30 Correct 12 ms 3172 KB Output is correct
31 Correct 14 ms 3160 KB Output is correct
32 Correct 11 ms 3168 KB Output is correct
33 Correct 32 ms 9684 KB Output is correct
34 Correct 33 ms 9684 KB Output is correct
35 Correct 37 ms 9108 KB Output is correct
36 Correct 110 ms 17764 KB Output is correct
37 Correct 122 ms 17880 KB Output is correct
38 Correct 126 ms 17908 KB Output is correct
39 Correct 111 ms 15204 KB Output is correct
40 Correct 116 ms 15296 KB Output is correct
41 Correct 115 ms 15240 KB Output is correct
42 Correct 58 ms 12960 KB Output is correct
43 Correct 98 ms 17608 KB Output is correct
44 Correct 94 ms 17652 KB Output is correct
45 Correct 103 ms 17604 KB Output is correct
46 Correct 111 ms 17604 KB Output is correct
47 Correct 102 ms 17604 KB Output is correct
48 Correct 98 ms 17728 KB Output is correct
49 Correct 111 ms 17604 KB Output is correct
50 Correct 102 ms 17856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1624 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 0 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 0 ms 1628 KB Output is correct
11 Correct 1 ms 1628 KB Output is correct
12 Correct 1 ms 1624 KB Output is correct
13 Correct 1 ms 1628 KB Output is correct
14 Correct 1 ms 1628 KB Output is correct
15 Correct 1 ms 1628 KB Output is correct
16 Correct 1 ms 1560 KB Output is correct
17 Correct 1 ms 1628 KB Output is correct
18 Correct 1 ms 1628 KB Output is correct
19 Correct 2 ms 1884 KB Output is correct
20 Correct 2 ms 1836 KB Output is correct
21 Correct 3 ms 1884 KB Output is correct
22 Correct 5 ms 2396 KB Output is correct
23 Correct 5 ms 2392 KB Output is correct
24 Correct 6 ms 2392 KB Output is correct
25 Correct 6 ms 2392 KB Output is correct
26 Correct 8 ms 2396 KB Output is correct
27 Correct 113 ms 22312 KB Output is correct
28 Correct 94 ms 22224 KB Output is correct
29 Correct 97 ms 23492 KB Output is correct
30 Correct 108 ms 22320 KB Output is correct
31 Correct 101 ms 22096 KB Output is correct
32 Correct 184 ms 30352 KB Output is correct
33 Correct 129 ms 23124 KB Output is correct
34 Correct 136 ms 24748 KB Output is correct
35 Correct 1 ms 1628 KB Output is correct
36 Correct 114 ms 17920 KB Output is correct
37 Correct 430 ms 49532 KB Output is correct
38 Correct 516 ms 49532 KB Output is correct
39 Correct 414 ms 45436 KB Output is correct
40 Correct 185 ms 23752 KB Output is correct
41 Correct 86 ms 13004 KB Output is correct
42 Correct 15 ms 3932 KB Output is correct
43 Correct 566 ms 48832 KB Output is correct
44 Correct 397 ms 43668 KB Output is correct
45 Correct 485 ms 49472 KB Output is correct
46 Correct 529 ms 48504 KB Output is correct
47 Correct 152 ms 30048 KB Output is correct
48 Correct 462 ms 49020 KB Output is correct
49 Correct 462 ms 49024 KB Output is correct
50 Correct 114 ms 26196 KB Output is correct
51 Correct 4 ms 2396 KB Output is correct
52 Correct 4 ms 2456 KB Output is correct
53 Correct 3 ms 2396 KB Output is correct
54 Correct 12 ms 3172 KB Output is correct
55 Correct 14 ms 3160 KB Output is correct
56 Correct 11 ms 3168 KB Output is correct
57 Correct 32 ms 9684 KB Output is correct
58 Correct 33 ms 9684 KB Output is correct
59 Correct 37 ms 9108 KB Output is correct
60 Correct 110 ms 17764 KB Output is correct
61 Correct 122 ms 17880 KB Output is correct
62 Correct 126 ms 17908 KB Output is correct
63 Correct 111 ms 15204 KB Output is correct
64 Correct 116 ms 15296 KB Output is correct
65 Correct 115 ms 15240 KB Output is correct
66 Correct 58 ms 12960 KB Output is correct
67 Correct 98 ms 17608 KB Output is correct
68 Correct 94 ms 17652 KB Output is correct
69 Correct 103 ms 17604 KB Output is correct
70 Correct 111 ms 17604 KB Output is correct
71 Correct 102 ms 17604 KB Output is correct
72 Correct 98 ms 17728 KB Output is correct
73 Correct 111 ms 17604 KB Output is correct
74 Correct 102 ms 17856 KB Output is correct
75 Correct 106 ms 24540 KB Output is correct
76 Correct 107 ms 24308 KB Output is correct
77 Correct 101 ms 25516 KB Output is correct
78 Correct 103 ms 25288 KB Output is correct
79 Correct 130 ms 24096 KB Output is correct
80 Correct 98 ms 25356 KB Output is correct
81 Correct 523 ms 49416 KB Output is correct
82 Correct 427 ms 49276 KB Output is correct
83 Correct 447 ms 49280 KB Output is correct
84 Correct 462 ms 49700 KB Output is correct
85 Correct 474 ms 49280 KB Output is correct
86 Correct 418 ms 49484 KB Output is correct
87 Correct 466 ms 49216 KB Output is correct
88 Correct 385 ms 41380 KB Output is correct
89 Correct 368 ms 41252 KB Output is correct
90 Correct 358 ms 41284 KB Output is correct
91 Correct 382 ms 41400 KB Output is correct
92 Correct 376 ms 41428 KB Output is correct
93 Correct 386 ms 48464 KB Output is correct
94 Correct 456 ms 48704 KB Output is correct
95 Correct 417 ms 48276 KB Output is correct
96 Correct 417 ms 48440 KB Output is correct
97 Correct 422 ms 48252 KB Output is correct
98 Correct 241 ms 35272 KB Output is correct
99 Correct 440 ms 48588 KB Output is correct
100 Correct 385 ms 48256 KB Output is correct
101 Correct 337 ms 40532 KB Output is correct
102 Correct 391 ms 47960 KB Output is correct
103 Correct 469 ms 47492 KB Output is correct
104 Correct 465 ms 48248 KB Output is correct
105 Correct 189 ms 36992 KB Output is correct
106 Correct 362 ms 47488 KB Output is correct
107 Correct 366 ms 47740 KB Output is correct
108 Correct 380 ms 47568 KB Output is correct
109 Correct 388 ms 47676 KB Output is correct
110 Correct 379 ms 47680 KB Output is correct
111 Correct 329 ms 47488 KB Output is correct
112 Correct 378 ms 47676 KB Output is correct
113 Correct 389 ms 47744 KB Output is correct
114 Correct 438 ms 47744 KB Output is correct
115 Correct 392 ms 47744 KB Output is correct
116 Correct 367 ms 47564 KB Output is correct