답안 #1033493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033493 2024-07-24T23:00:36 Z crimson231 원 고르기 (APIO18_circle_selection) C++17
100 / 100
537 ms 41596 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, M, Q;
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; }
} INVAL = { { 0, 0 }, -1 };
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 1 ms 1372 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1624 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 1628 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 1472 KB Output is correct
19 Correct 2 ms 1884 KB Output is correct
20 Correct 4 ms 1884 KB Output is correct
21 Correct 2 ms 1684 KB Output is correct
22 Correct 6 ms 2192 KB Output is correct
23 Correct 6 ms 2140 KB Output is correct
24 Correct 6 ms 2140 KB Output is correct
25 Correct 7 ms 2140 KB Output is correct
26 Correct 6 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 15660 KB Output is correct
2 Correct 110 ms 15568 KB Output is correct
3 Correct 111 ms 16916 KB Output is correct
4 Correct 109 ms 15412 KB Output is correct
5 Correct 113 ms 17588 KB Output is correct
6 Correct 228 ms 25700 KB Output is correct
7 Correct 126 ms 18260 KB Output is correct
8 Correct 139 ms 20144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 127 ms 15068 KB Output is correct
3 Correct 422 ms 41340 KB Output is correct
4 Correct 513 ms 41344 KB Output is correct
5 Correct 456 ms 37248 KB Output is correct
6 Correct 180 ms 19288 KB Output is correct
7 Correct 81 ms 10848 KB Output is correct
8 Correct 14 ms 3420 KB Output is correct
9 Correct 537 ms 40576 KB Output is correct
10 Correct 361 ms 35200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 460 ms 41424 KB Output is correct
2 Correct 490 ms 41596 KB Output is correct
3 Correct 156 ms 21448 KB Output is correct
4 Correct 402 ms 41344 KB Output is correct
5 Correct 422 ms 41436 KB Output is correct
6 Correct 119 ms 17492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1624 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 1628 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 1472 KB Output is correct
19 Correct 2 ms 1884 KB Output is correct
20 Correct 4 ms 1884 KB Output is correct
21 Correct 2 ms 1684 KB Output is correct
22 Correct 6 ms 2192 KB Output is correct
23 Correct 6 ms 2140 KB Output is correct
24 Correct 6 ms 2140 KB Output is correct
25 Correct 7 ms 2140 KB Output is correct
26 Correct 6 ms 2140 KB Output is correct
27 Correct 4 ms 2136 KB Output is correct
28 Correct 4 ms 2136 KB Output is correct
29 Correct 4 ms 2140 KB Output is correct
30 Correct 12 ms 2908 KB Output is correct
31 Correct 12 ms 2908 KB Output is correct
32 Correct 12 ms 2908 KB Output is correct
33 Correct 36 ms 6608 KB Output is correct
34 Correct 37 ms 6608 KB Output is correct
35 Correct 43 ms 6560 KB Output is correct
36 Correct 125 ms 15304 KB Output is correct
37 Correct 121 ms 15232 KB Output is correct
38 Correct 125 ms 15556 KB Output is correct
39 Correct 128 ms 14136 KB Output is correct
40 Correct 118 ms 14152 KB Output is correct
41 Correct 118 ms 14204 KB Output is correct
42 Correct 64 ms 11360 KB Output is correct
43 Correct 113 ms 15044 KB Output is correct
44 Correct 108 ms 15048 KB Output is correct
45 Correct 134 ms 15044 KB Output is correct
46 Correct 109 ms 15000 KB Output is correct
47 Correct 108 ms 15044 KB Output is correct
48 Correct 110 ms 15044 KB Output is correct
49 Correct 110 ms 15048 KB Output is correct
50 Correct 109 ms 15056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1624 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 1628 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 1472 KB Output is correct
19 Correct 2 ms 1884 KB Output is correct
20 Correct 4 ms 1884 KB Output is correct
21 Correct 2 ms 1684 KB Output is correct
22 Correct 6 ms 2192 KB Output is correct
23 Correct 6 ms 2140 KB Output is correct
24 Correct 6 ms 2140 KB Output is correct
25 Correct 7 ms 2140 KB Output is correct
26 Correct 6 ms 2140 KB Output is correct
27 Correct 120 ms 15660 KB Output is correct
28 Correct 110 ms 15568 KB Output is correct
29 Correct 111 ms 16916 KB Output is correct
30 Correct 109 ms 15412 KB Output is correct
31 Correct 113 ms 17588 KB Output is correct
32 Correct 228 ms 25700 KB Output is correct
33 Correct 126 ms 18260 KB Output is correct
34 Correct 139 ms 20144 KB Output is correct
35 Correct 1 ms 1628 KB Output is correct
36 Correct 127 ms 15068 KB Output is correct
37 Correct 422 ms 41340 KB Output is correct
38 Correct 513 ms 41344 KB Output is correct
39 Correct 456 ms 37248 KB Output is correct
40 Correct 180 ms 19288 KB Output is correct
41 Correct 81 ms 10848 KB Output is correct
42 Correct 14 ms 3420 KB Output is correct
43 Correct 537 ms 40576 KB Output is correct
44 Correct 361 ms 35200 KB Output is correct
45 Correct 460 ms 41424 KB Output is correct
46 Correct 490 ms 41596 KB Output is correct
47 Correct 156 ms 21448 KB Output is correct
48 Correct 402 ms 41344 KB Output is correct
49 Correct 422 ms 41436 KB Output is correct
50 Correct 119 ms 17492 KB Output is correct
51 Correct 4 ms 2136 KB Output is correct
52 Correct 4 ms 2136 KB Output is correct
53 Correct 4 ms 2140 KB Output is correct
54 Correct 12 ms 2908 KB Output is correct
55 Correct 12 ms 2908 KB Output is correct
56 Correct 12 ms 2908 KB Output is correct
57 Correct 36 ms 6608 KB Output is correct
58 Correct 37 ms 6608 KB Output is correct
59 Correct 43 ms 6560 KB Output is correct
60 Correct 125 ms 15304 KB Output is correct
61 Correct 121 ms 15232 KB Output is correct
62 Correct 125 ms 15556 KB Output is correct
63 Correct 128 ms 14136 KB Output is correct
64 Correct 118 ms 14152 KB Output is correct
65 Correct 118 ms 14204 KB Output is correct
66 Correct 64 ms 11360 KB Output is correct
67 Correct 113 ms 15044 KB Output is correct
68 Correct 108 ms 15048 KB Output is correct
69 Correct 134 ms 15044 KB Output is correct
70 Correct 109 ms 15000 KB Output is correct
71 Correct 108 ms 15044 KB Output is correct
72 Correct 110 ms 15044 KB Output is correct
73 Correct 110 ms 15048 KB Output is correct
74 Correct 109 ms 15056 KB Output is correct
75 Correct 112 ms 15136 KB Output is correct
76 Correct 109 ms 15700 KB Output is correct
77 Correct 110 ms 16600 KB Output is correct
78 Correct 104 ms 16328 KB Output is correct
79 Correct 134 ms 15388 KB Output is correct
80 Correct 103 ms 16328 KB Output is correct
81 Correct 531 ms 41596 KB Output is correct
82 Correct 424 ms 41340 KB Output is correct
83 Correct 439 ms 41340 KB Output is correct
84 Correct 463 ms 41336 KB Output is correct
85 Correct 460 ms 41596 KB Output is correct
86 Correct 444 ms 41384 KB Output is correct
87 Correct 511 ms 41156 KB Output is correct
88 Correct 379 ms 37788 KB Output is correct
89 Correct 420 ms 37924 KB Output is correct
90 Correct 403 ms 37956 KB Output is correct
91 Correct 384 ms 37852 KB Output is correct
92 Correct 421 ms 37880 KB Output is correct
93 Correct 445 ms 41552 KB Output is correct
94 Correct 422 ms 41180 KB Output is correct
95 Correct 476 ms 41392 KB Output is correct
96 Correct 462 ms 41444 KB Output is correct
97 Correct 413 ms 41420 KB Output is correct
98 Correct 294 ms 27940 KB Output is correct
99 Correct 483 ms 41436 KB Output is correct
100 Correct 454 ms 41392 KB Output is correct
101 Correct 308 ms 33156 KB Output is correct
102 Correct 431 ms 40828 KB Output is correct
103 Correct 493 ms 40400 KB Output is correct
104 Correct 460 ms 41464 KB Output is correct
105 Correct 209 ms 31924 KB Output is correct
106 Correct 367 ms 39808 KB Output is correct
107 Correct 381 ms 40064 KB Output is correct
108 Correct 392 ms 39908 KB Output is correct
109 Correct 385 ms 39816 KB Output is correct
110 Correct 342 ms 39804 KB Output is correct
111 Correct 374 ms 39804 KB Output is correct
112 Correct 374 ms 39904 KB Output is correct
113 Correct 424 ms 39804 KB Output is correct
114 Correct 358 ms 39828 KB Output is correct
115 Correct 378 ms 40064 KB Output is correct
116 Correct 371 ms 39880 KB Output is correct