답안 #258974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258974 2020-08-06T22:20:10 Z amoo_safar 원 고르기 (APIO18_circle_selection) C++17
100 / 100
777 ms 28752 KB
// Null
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
 
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const ll Mod = 1000000007LL;
const int N = 3e5 + 10;
const int Inf = 2e9;

int n, x[N], y[N], r[N];
int mk[N];

vector<pii> V[N];
vector<int> U, X, Y;

void Build(int L){
	for(int i = 0; i < (int) U.size(); i++) V[i].clear();
	U.clear();

	for(int i : X){
		if(mk[i]) continue;
		U.pb(x[i] / L);
	}
	//sort(all(U));
	U.resize(unique(all(U)) - U.begin() );
	for(int i : Y)
		if(!mk[i])
			V[lower_bound(all(U), x[i] / L) - U.begin()].pb({y[i] / L, i});
	for(int i = 0; i < (int) U.size(); i++)
		sort(all(V[i]));
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x[i] >> y[i] >> r[i];
		X.pb(i);
		Y.pb(i);
	}
	vector<int> I(n); iota(all(I), 1);
	sort(all(I), [&](int i, int j){
		return (r[i] == r[j] ? i < j : r[i] > r[j]);
	});
	sort(all(X), [&](int i, int j){
		return x[i] < x[j];
	});
	sort(all(Y), [&](int i, int j){
		return y[i] < y[j];
	});

	int L = r[I[0]];
	Build(L);
	for(auto id : I){
		if(mk[id]) continue;
		if(L >= 4*r[id]) Build(L = r[id]);

		int i = x[id] / L;
		int j = y[id] / L;

		int nei;
		for(int pos = lower_bound(all(U), i - 2) - U.begin(); pos < (int) U.size() && U[pos] <= i + 2; pos ++){

			for(int posj = lower_bound(all(V[pos]), pii(j - 2, -1)) - V[pos].begin(); posj < (int) V[pos].size() && V[pos][posj].F <= j + 2; posj ++){
				nei = V[pos][posj].S;
				if(mk[nei]) continue;
				if(1ll*(x[id] - x[nei])*(x[id] - x[nei]) + 1ll*(y[id] - y[nei])*(y[id] - y[nei]) <= 1ll*(r[id] + r[nei])*(r[id] + r[nei]) ){
					mk[nei] = id;
				}
			}
		}
	}
	
	for(int i = 1; i <= n; i++) cout << mk[i] << ' ';
	cout << '\n';
	return 0;
}
/*
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

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 6 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 6 ms 7424 KB Output is correct
12 Correct 4 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 6 ms 7424 KB Output is correct
15 Correct 6 ms 7424 KB Output is correct
16 Correct 6 ms 7424 KB Output is correct
17 Correct 6 ms 7424 KB Output is correct
18 Correct 6 ms 7424 KB Output is correct
19 Correct 10 ms 7808 KB Output is correct
20 Correct 10 ms 7760 KB Output is correct
21 Correct 10 ms 7808 KB Output is correct
22 Correct 11 ms 7808 KB Output is correct
23 Correct 10 ms 7808 KB Output is correct
24 Correct 12 ms 7808 KB Output is correct
25 Correct 10 ms 7808 KB Output is correct
26 Correct 11 ms 7808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 268 ms 21700 KB Output is correct
2 Correct 267 ms 23140 KB Output is correct
3 Correct 266 ms 23760 KB Output is correct
4 Correct 280 ms 21740 KB Output is correct
5 Correct 292 ms 22732 KB Output is correct
6 Correct 416 ms 24924 KB Output is correct
7 Correct 308 ms 23372 KB Output is correct
8 Correct 324 ms 23508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 159 ms 13036 KB Output is correct
3 Correct 546 ms 23880 KB Output is correct
4 Correct 536 ms 24052 KB Output is correct
5 Correct 506 ms 23380 KB Output is correct
6 Correct 228 ms 15712 KB Output is correct
7 Correct 109 ms 11852 KB Output is correct
8 Correct 25 ms 8448 KB Output is correct
9 Correct 564 ms 24364 KB Output is correct
10 Correct 514 ms 24120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 533 ms 23888 KB Output is correct
2 Correct 532 ms 28752 KB Output is correct
3 Correct 348 ms 22100 KB Output is correct
4 Correct 575 ms 27928 KB Output is correct
5 Correct 585 ms 28336 KB Output is correct
6 Correct 334 ms 21264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 6 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 6 ms 7424 KB Output is correct
12 Correct 4 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 6 ms 7424 KB Output is correct
15 Correct 6 ms 7424 KB Output is correct
16 Correct 6 ms 7424 KB Output is correct
17 Correct 6 ms 7424 KB Output is correct
18 Correct 6 ms 7424 KB Output is correct
19 Correct 10 ms 7808 KB Output is correct
20 Correct 10 ms 7760 KB Output is correct
21 Correct 10 ms 7808 KB Output is correct
22 Correct 11 ms 7808 KB Output is correct
23 Correct 10 ms 7808 KB Output is correct
24 Correct 12 ms 7808 KB Output is correct
25 Correct 10 ms 7808 KB Output is correct
26 Correct 11 ms 7808 KB Output is correct
27 Correct 15 ms 8092 KB Output is correct
28 Correct 13 ms 8064 KB Output is correct
29 Correct 14 ms 8064 KB Output is correct
30 Correct 17 ms 8064 KB Output is correct
31 Correct 17 ms 8064 KB Output is correct
32 Correct 18 ms 8064 KB Output is correct
33 Correct 120 ms 12328 KB Output is correct
34 Correct 122 ms 12640 KB Output is correct
35 Correct 109 ms 12652 KB Output is correct
36 Correct 167 ms 13164 KB Output is correct
37 Correct 163 ms 13048 KB Output is correct
38 Correct 160 ms 12888 KB Output is correct
39 Correct 251 ms 14152 KB Output is correct
40 Correct 238 ms 13288 KB Output is correct
41 Correct 242 ms 14172 KB Output is correct
42 Correct 95 ms 12652 KB Output is correct
43 Correct 131 ms 14316 KB Output is correct
44 Correct 134 ms 14440 KB Output is correct
45 Correct 134 ms 14316 KB Output is correct
46 Correct 137 ms 14444 KB Output is correct
47 Correct 127 ms 14324 KB Output is correct
48 Correct 133 ms 14424 KB Output is correct
49 Correct 131 ms 14440 KB Output is correct
50 Correct 137 ms 14444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 6 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 6 ms 7424 KB Output is correct
12 Correct 4 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 6 ms 7424 KB Output is correct
15 Correct 6 ms 7424 KB Output is correct
16 Correct 6 ms 7424 KB Output is correct
17 Correct 6 ms 7424 KB Output is correct
18 Correct 6 ms 7424 KB Output is correct
19 Correct 10 ms 7808 KB Output is correct
20 Correct 10 ms 7760 KB Output is correct
21 Correct 10 ms 7808 KB Output is correct
22 Correct 11 ms 7808 KB Output is correct
23 Correct 10 ms 7808 KB Output is correct
24 Correct 12 ms 7808 KB Output is correct
25 Correct 10 ms 7808 KB Output is correct
26 Correct 11 ms 7808 KB Output is correct
27 Correct 268 ms 21700 KB Output is correct
28 Correct 267 ms 23140 KB Output is correct
29 Correct 266 ms 23760 KB Output is correct
30 Correct 280 ms 21740 KB Output is correct
31 Correct 292 ms 22732 KB Output is correct
32 Correct 416 ms 24924 KB Output is correct
33 Correct 308 ms 23372 KB Output is correct
34 Correct 324 ms 23508 KB Output is correct
35 Correct 5 ms 7424 KB Output is correct
36 Correct 159 ms 13036 KB Output is correct
37 Correct 546 ms 23880 KB Output is correct
38 Correct 536 ms 24052 KB Output is correct
39 Correct 506 ms 23380 KB Output is correct
40 Correct 228 ms 15712 KB Output is correct
41 Correct 109 ms 11852 KB Output is correct
42 Correct 25 ms 8448 KB Output is correct
43 Correct 564 ms 24364 KB Output is correct
44 Correct 514 ms 24120 KB Output is correct
45 Correct 533 ms 23888 KB Output is correct
46 Correct 532 ms 28752 KB Output is correct
47 Correct 348 ms 22100 KB Output is correct
48 Correct 575 ms 27928 KB Output is correct
49 Correct 585 ms 28336 KB Output is correct
50 Correct 334 ms 21264 KB Output is correct
51 Correct 15 ms 8092 KB Output is correct
52 Correct 13 ms 8064 KB Output is correct
53 Correct 14 ms 8064 KB Output is correct
54 Correct 17 ms 8064 KB Output is correct
55 Correct 17 ms 8064 KB Output is correct
56 Correct 18 ms 8064 KB Output is correct
57 Correct 120 ms 12328 KB Output is correct
58 Correct 122 ms 12640 KB Output is correct
59 Correct 109 ms 12652 KB Output is correct
60 Correct 167 ms 13164 KB Output is correct
61 Correct 163 ms 13048 KB Output is correct
62 Correct 160 ms 12888 KB Output is correct
63 Correct 251 ms 14152 KB Output is correct
64 Correct 238 ms 13288 KB Output is correct
65 Correct 242 ms 14172 KB Output is correct
66 Correct 95 ms 12652 KB Output is correct
67 Correct 131 ms 14316 KB Output is correct
68 Correct 134 ms 14440 KB Output is correct
69 Correct 134 ms 14316 KB Output is correct
70 Correct 137 ms 14444 KB Output is correct
71 Correct 127 ms 14324 KB Output is correct
72 Correct 133 ms 14424 KB Output is correct
73 Correct 131 ms 14440 KB Output is correct
74 Correct 137 ms 14444 KB Output is correct
75 Correct 358 ms 23828 KB Output is correct
76 Correct 323 ms 23500 KB Output is correct
77 Correct 339 ms 21956 KB Output is correct
78 Correct 358 ms 21580 KB Output is correct
79 Correct 347 ms 22092 KB Output is correct
80 Correct 361 ms 21656 KB Output is correct
81 Correct 568 ms 23884 KB Output is correct
82 Correct 587 ms 23756 KB Output is correct
83 Correct 564 ms 23956 KB Output is correct
84 Correct 532 ms 23864 KB Output is correct
85 Correct 542 ms 23884 KB Output is correct
86 Correct 580 ms 23628 KB Output is correct
87 Correct 538 ms 24252 KB Output is correct
88 Correct 760 ms 27712 KB Output is correct
89 Correct 777 ms 25564 KB Output is correct
90 Correct 769 ms 27776 KB Output is correct
91 Correct 770 ms 27884 KB Output is correct
92 Correct 755 ms 25428 KB Output is correct
93 Correct 560 ms 28504 KB Output is correct
94 Correct 376 ms 22472 KB Output is correct
95 Correct 560 ms 28500 KB Output is correct
96 Correct 579 ms 28368 KB Output is correct
97 Correct 544 ms 23120 KB Output is correct
98 Correct 520 ms 24532 KB Output is correct
99 Correct 570 ms 28628 KB Output is correct
100 Correct 529 ms 28620 KB Output is correct
101 Correct 504 ms 23764 KB Output is correct
102 Correct 557 ms 28244 KB Output is correct
103 Correct 473 ms 23376 KB Output is correct
104 Correct 589 ms 28752 KB Output is correct
105 Correct 311 ms 23716 KB Output is correct
106 Correct 408 ms 26584 KB Output is correct
107 Correct 417 ms 26652 KB Output is correct
108 Correct 464 ms 26580 KB Output is correct
109 Correct 432 ms 26572 KB Output is correct
110 Correct 417 ms 26572 KB Output is correct
111 Correct 414 ms 26580 KB Output is correct
112 Correct 448 ms 26820 KB Output is correct
113 Correct 425 ms 26576 KB Output is correct
114 Correct 411 ms 26576 KB Output is correct
115 Correct 489 ms 26612 KB Output is correct
116 Correct 408 ms 27864 KB Output is correct