답안 #1033548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033548 2024-07-25T03:31:22 Z crimson231 원 고르기 (APIO18_circle_selection) C++17
100 / 100
601 ms 49872 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;
		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 1 ms 1628 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 1 ms 1624 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 1 ms 1628 KB Output is correct
11 Correct 1 ms 1488 KB Output is correct
12 Correct 1 ms 1628 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 1628 KB Output is correct
17 Correct 1 ms 1628 KB Output is correct
18 Correct 1 ms 1628 KB Output is correct
19 Correct 3 ms 1836 KB Output is correct
20 Correct 3 ms 1884 KB Output is correct
21 Correct 2 ms 2048 KB Output is correct
22 Correct 6 ms 2396 KB Output is correct
23 Correct 7 ms 2396 KB Output is correct
24 Correct 8 ms 2392 KB Output is correct
25 Correct 6 ms 2396 KB Output is correct
26 Correct 6 ms 2332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 22312 KB Output is correct
2 Correct 106 ms 22224 KB Output is correct
3 Correct 111 ms 23492 KB Output is correct
4 Correct 104 ms 22320 KB Output is correct
5 Correct 112 ms 22096 KB Output is correct
6 Correct 247 ms 30540 KB Output is correct
7 Correct 126 ms 23120 KB Output is correct
8 Correct 134 ms 24748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 125 ms 17936 KB Output is correct
3 Correct 564 ms 49548 KB Output is correct
4 Correct 516 ms 49528 KB Output is correct
5 Correct 467 ms 45432 KB Output is correct
6 Correct 165 ms 23748 KB Output is correct
7 Correct 84 ms 13000 KB Output is correct
8 Correct 13 ms 3932 KB Output is correct
9 Correct 492 ms 48680 KB Output is correct
10 Correct 370 ms 43596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 501 ms 49544 KB Output is correct
2 Correct 428 ms 48592 KB Output is correct
3 Correct 157 ms 30308 KB Output is correct
4 Correct 467 ms 48828 KB Output is correct
5 Correct 486 ms 49004 KB Output is correct
6 Correct 122 ms 26196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1628 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 1 ms 1624 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 1 ms 1628 KB Output is correct
11 Correct 1 ms 1488 KB Output is correct
12 Correct 1 ms 1628 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 1628 KB Output is correct
17 Correct 1 ms 1628 KB Output is correct
18 Correct 1 ms 1628 KB Output is correct
19 Correct 3 ms 1836 KB Output is correct
20 Correct 3 ms 1884 KB Output is correct
21 Correct 2 ms 2048 KB Output is correct
22 Correct 6 ms 2396 KB Output is correct
23 Correct 7 ms 2396 KB Output is correct
24 Correct 8 ms 2392 KB Output is correct
25 Correct 6 ms 2396 KB Output is correct
26 Correct 6 ms 2332 KB Output is correct
27 Correct 4 ms 2396 KB Output is correct
28 Correct 4 ms 2396 KB Output is correct
29 Correct 4 ms 2396 KB Output is correct
30 Correct 12 ms 3164 KB Output is correct
31 Correct 13 ms 3164 KB Output is correct
32 Correct 12 ms 3164 KB Output is correct
33 Correct 43 ms 9612 KB Output is correct
34 Correct 40 ms 9684 KB Output is correct
35 Correct 40 ms 9088 KB Output is correct
36 Correct 143 ms 17864 KB Output is correct
37 Correct 126 ms 17876 KB Output is correct
38 Correct 141 ms 17860 KB Output is correct
39 Correct 177 ms 15248 KB Output is correct
40 Correct 159 ms 15248 KB Output is correct
41 Correct 163 ms 15224 KB Output is correct
42 Correct 56 ms 13156 KB Output is correct
43 Correct 109 ms 17608 KB Output is correct
44 Correct 110 ms 17668 KB Output is correct
45 Correct 110 ms 17860 KB Output is correct
46 Correct 102 ms 17608 KB Output is correct
47 Correct 111 ms 17660 KB Output is correct
48 Correct 108 ms 17612 KB Output is correct
49 Correct 108 ms 17524 KB Output is correct
50 Correct 108 ms 17604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1628 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 1 ms 1624 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 1 ms 1628 KB Output is correct
11 Correct 1 ms 1488 KB Output is correct
12 Correct 1 ms 1628 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 1628 KB Output is correct
17 Correct 1 ms 1628 KB Output is correct
18 Correct 1 ms 1628 KB Output is correct
19 Correct 3 ms 1836 KB Output is correct
20 Correct 3 ms 1884 KB Output is correct
21 Correct 2 ms 2048 KB Output is correct
22 Correct 6 ms 2396 KB Output is correct
23 Correct 7 ms 2396 KB Output is correct
24 Correct 8 ms 2392 KB Output is correct
25 Correct 6 ms 2396 KB Output is correct
26 Correct 6 ms 2332 KB Output is correct
27 Correct 105 ms 22312 KB Output is correct
28 Correct 106 ms 22224 KB Output is correct
29 Correct 111 ms 23492 KB Output is correct
30 Correct 104 ms 22320 KB Output is correct
31 Correct 112 ms 22096 KB Output is correct
32 Correct 247 ms 30540 KB Output is correct
33 Correct 126 ms 23120 KB Output is correct
34 Correct 134 ms 24748 KB Output is correct
35 Correct 1 ms 1624 KB Output is correct
36 Correct 125 ms 17936 KB Output is correct
37 Correct 564 ms 49548 KB Output is correct
38 Correct 516 ms 49528 KB Output is correct
39 Correct 467 ms 45432 KB Output is correct
40 Correct 165 ms 23748 KB Output is correct
41 Correct 84 ms 13000 KB Output is correct
42 Correct 13 ms 3932 KB Output is correct
43 Correct 492 ms 48680 KB Output is correct
44 Correct 370 ms 43596 KB Output is correct
45 Correct 501 ms 49544 KB Output is correct
46 Correct 428 ms 48592 KB Output is correct
47 Correct 157 ms 30308 KB Output is correct
48 Correct 467 ms 48828 KB Output is correct
49 Correct 486 ms 49004 KB Output is correct
50 Correct 122 ms 26196 KB Output is correct
51 Correct 4 ms 2396 KB Output is correct
52 Correct 4 ms 2396 KB Output is correct
53 Correct 4 ms 2396 KB Output is correct
54 Correct 12 ms 3164 KB Output is correct
55 Correct 13 ms 3164 KB Output is correct
56 Correct 12 ms 3164 KB Output is correct
57 Correct 43 ms 9612 KB Output is correct
58 Correct 40 ms 9684 KB Output is correct
59 Correct 40 ms 9088 KB Output is correct
60 Correct 143 ms 17864 KB Output is correct
61 Correct 126 ms 17876 KB Output is correct
62 Correct 141 ms 17860 KB Output is correct
63 Correct 177 ms 15248 KB Output is correct
64 Correct 159 ms 15248 KB Output is correct
65 Correct 163 ms 15224 KB Output is correct
66 Correct 56 ms 13156 KB Output is correct
67 Correct 109 ms 17608 KB Output is correct
68 Correct 110 ms 17668 KB Output is correct
69 Correct 110 ms 17860 KB Output is correct
70 Correct 102 ms 17608 KB Output is correct
71 Correct 111 ms 17660 KB Output is correct
72 Correct 108 ms 17612 KB Output is correct
73 Correct 108 ms 17524 KB Output is correct
74 Correct 108 ms 17604 KB Output is correct
75 Correct 145 ms 24416 KB Output is correct
76 Correct 115 ms 24516 KB Output is correct
77 Correct 117 ms 25508 KB Output is correct
78 Correct 112 ms 25492 KB Output is correct
79 Correct 136 ms 24100 KB Output is correct
80 Correct 106 ms 25484 KB Output is correct
81 Correct 538 ms 49420 KB Output is correct
82 Correct 503 ms 49356 KB Output is correct
83 Correct 469 ms 49240 KB Output is correct
84 Correct 449 ms 49872 KB Output is correct
85 Correct 487 ms 49332 KB Output is correct
86 Correct 418 ms 49536 KB Output is correct
87 Correct 466 ms 49232 KB Output is correct
88 Correct 525 ms 41276 KB Output is correct
89 Correct 598 ms 41424 KB Output is correct
90 Correct 513 ms 41532 KB Output is correct
91 Correct 547 ms 41304 KB Output is correct
92 Correct 601 ms 41452 KB Output is correct
93 Correct 487 ms 48444 KB Output is correct
94 Correct 571 ms 48644 KB Output is correct
95 Correct 540 ms 48512 KB Output is correct
96 Correct 436 ms 48452 KB Output is correct
97 Correct 453 ms 48284 KB Output is correct
98 Correct 302 ms 35356 KB Output is correct
99 Correct 451 ms 48508 KB Output is correct
100 Correct 448 ms 48188 KB Output is correct
101 Correct 349 ms 40568 KB Output is correct
102 Correct 425 ms 47996 KB Output is correct
103 Correct 556 ms 47552 KB Output is correct
104 Correct 477 ms 48332 KB Output is correct
105 Correct 225 ms 36992 KB Output is correct
106 Correct 385 ms 47480 KB Output is correct
107 Correct 371 ms 47748 KB Output is correct
108 Correct 401 ms 47740 KB Output is correct
109 Correct 375 ms 47740 KB Output is correct
110 Correct 413 ms 47740 KB Output is correct
111 Correct 425 ms 47676 KB Output is correct
112 Correct 377 ms 47560 KB Output is correct
113 Correct 411 ms 47796 KB Output is correct
114 Correct 365 ms 47596 KB Output is correct
115 Correct 446 ms 47580 KB Output is correct
116 Correct 403 ms 47672 KB Output is correct