답안 #544199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544199 2022-04-01T10:08:41 Z amunduzbaev 원 고르기 (APIO18_circle_selection) C++17
100 / 100
2646 ms 42324 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
#define int long long
const double eps = 1e-9;

struct poi{
	int x, y, r;
};

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	vector<poi> a(n);
	vector<vector<ar<int, 2>>> pp;
	vector<int> used(n), tot, par(n);
	int R;
	auto get = [&](int x){ 
		if(x >= 0) return x / R;
		else {
			return (x + 1) / R - 1;
		}
	};
	
	auto rec = [&](){
		pp.clear(); tot.clear();
		for(int i=0;i<n;i++) {
			if(used[i]) continue;
			tot.push_back(get(a[i].x));
		}
		sort(tot.begin(), tot.end());
		tot.erase(unique(tot.begin(), tot.end()), tot.end());
		pp.resize(tot.size());
		for(int i=0;i<n;i++){
			if(used[i]) continue;
			auto j = lower_bound(tot.begin(), tot.end(), get(a[i].x)) - tot.begin();
			//~ assert(j < (int)tot.size());
			pp[j].push_back({a[i].y, i});
		}
		
		for(int i=0;i<(int)tot.size();i++){
			sort(pp[i].begin(), pp[i].end());
			for(int j=0;j<(int)pp[i].size();j++){
				par[pp[i][j][1]] = j + 1;
			}
		}
	};
	
	vector<int> p(n); 
	for(int i=0;i<n;i++){
		p[i] = i;
		cin>>a[i].x>>a[i].y>>a[i].r;
	}
	sort(p.begin(), p.end(), [&](int i, int j){
		if(a[i].r != a[j].r)
			return (a[i].r > a[j].r);
		else 
			return i < j;
	});
	
	auto sq = [&](int x) { return x * 1ll * x; };
	auto dis = [&](int i, int j) -> double{
		return sqrt(sq(a[i].x - a[j].x) + sq(a[i].y - a[j].y));
	};
	
	auto check = [&](int i, int j){
		return (a[i].r + a[j].r >= dis(i, j));
	};
	
	R = a[p[0]].r;
	rec();
	for(auto i : p){
		if(used[i]) continue;
		if(a[i].r * 2 <= R) R = a[i].r, rec();
		int l = lower_bound(tot.begin(), tot.end(), get(a[i].x) - 2) - tot.begin();
		int r = upper_bound(tot.begin(), tot.end(), get(a[i].x) + 2) - tot.begin();
		int lx = (get(a[i].y) - 2) * R;
		int rx = (get(a[i].y) + 3) * R;
		
		function<int(int, int)> f = [&](int j, int i){
			if(i >= (int)pp[j].size() || !used[pp[j][i][1]]) return i;
			par[pp[j][i][1]] = f(j, par[pp[j][i][1]]);
			return par[pp[j][i][1]];
		};
		
		for(int j=l;j<r;j++){
			int it = lower_bound(pp[j].begin(), pp[j].end(), (ar<int, 2>){lx, -1}) - pp[j].begin();
			it = f(j, it);
			while(it < (int)pp[j].size() && pp[j][it][0] < rx){
				if(check(pp[j][it][1], i)){
					used[pp[j][it][1]] = i + 1;
				}
				
				it = par[pp[j][it][1]];
				it = f(j, it);
			}
		}
	}
	
	for(int i=0;i<n;i++) cout<<used[i]<<" ";
	cout<<"\n";
}

/*

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 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 852 KB Output is correct
22 Correct 6 ms 724 KB Output is correct
23 Correct 6 ms 724 KB Output is correct
24 Correct 6 ms 724 KB Output is correct
25 Correct 6 ms 852 KB Output is correct
26 Correct 6 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 24904 KB Output is correct
2 Correct 181 ms 27460 KB Output is correct
3 Correct 180 ms 33864 KB Output is correct
4 Correct 174 ms 24892 KB Output is correct
5 Correct 232 ms 26432 KB Output is correct
6 Correct 412 ms 30492 KB Output is correct
7 Correct 278 ms 27756 KB Output is correct
8 Correct 288 ms 28092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 149 ms 9508 KB Output is correct
3 Correct 603 ms 27152 KB Output is correct
4 Correct 631 ms 27864 KB Output is correct
5 Correct 532 ms 24756 KB Output is correct
6 Correct 229 ms 13748 KB Output is correct
7 Correct 95 ms 7648 KB Output is correct
8 Correct 25 ms 2000 KB Output is correct
9 Correct 708 ms 26808 KB Output is correct
10 Correct 544 ms 25148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 600 ms 28444 KB Output is correct
2 Correct 398 ms 35136 KB Output is correct
3 Correct 296 ms 25064 KB Output is correct
4 Correct 495 ms 34760 KB Output is correct
5 Correct 481 ms 35244 KB Output is correct
6 Correct 262 ms 24088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 852 KB Output is correct
22 Correct 6 ms 724 KB Output is correct
23 Correct 6 ms 724 KB Output is correct
24 Correct 6 ms 724 KB Output is correct
25 Correct 6 ms 852 KB Output is correct
26 Correct 6 ms 724 KB Output is correct
27 Correct 6 ms 1188 KB Output is correct
28 Correct 9 ms 1236 KB Output is correct
29 Correct 8 ms 1108 KB Output is correct
30 Correct 14 ms 1264 KB Output is correct
31 Correct 21 ms 1268 KB Output is correct
32 Correct 12 ms 1300 KB Output is correct
33 Correct 66 ms 8044 KB Output is correct
34 Correct 70 ms 8860 KB Output is correct
35 Correct 81 ms 10140 KB Output is correct
36 Correct 188 ms 10084 KB Output is correct
37 Correct 191 ms 10292 KB Output is correct
38 Correct 180 ms 10000 KB Output is correct
39 Correct 614 ms 9568 KB Output is correct
40 Correct 596 ms 9696 KB Output is correct
41 Correct 607 ms 9380 KB Output is correct
42 Correct 91 ms 9672 KB Output is correct
43 Correct 105 ms 12192 KB Output is correct
44 Correct 135 ms 12300 KB Output is correct
45 Correct 120 ms 12144 KB Output is correct
46 Correct 111 ms 12204 KB Output is correct
47 Correct 111 ms 12160 KB Output is correct
48 Correct 111 ms 12216 KB Output is correct
49 Correct 106 ms 12188 KB Output is correct
50 Correct 105 ms 12196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 852 KB Output is correct
22 Correct 6 ms 724 KB Output is correct
23 Correct 6 ms 724 KB Output is correct
24 Correct 6 ms 724 KB Output is correct
25 Correct 6 ms 852 KB Output is correct
26 Correct 6 ms 724 KB Output is correct
27 Correct 178 ms 24904 KB Output is correct
28 Correct 181 ms 27460 KB Output is correct
29 Correct 180 ms 33864 KB Output is correct
30 Correct 174 ms 24892 KB Output is correct
31 Correct 232 ms 26432 KB Output is correct
32 Correct 412 ms 30492 KB Output is correct
33 Correct 278 ms 27756 KB Output is correct
34 Correct 288 ms 28092 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 149 ms 9508 KB Output is correct
37 Correct 603 ms 27152 KB Output is correct
38 Correct 631 ms 27864 KB Output is correct
39 Correct 532 ms 24756 KB Output is correct
40 Correct 229 ms 13748 KB Output is correct
41 Correct 95 ms 7648 KB Output is correct
42 Correct 25 ms 2000 KB Output is correct
43 Correct 708 ms 26808 KB Output is correct
44 Correct 544 ms 25148 KB Output is correct
45 Correct 600 ms 28444 KB Output is correct
46 Correct 398 ms 35136 KB Output is correct
47 Correct 296 ms 25064 KB Output is correct
48 Correct 495 ms 34760 KB Output is correct
49 Correct 481 ms 35244 KB Output is correct
50 Correct 262 ms 24088 KB Output is correct
51 Correct 6 ms 1188 KB Output is correct
52 Correct 9 ms 1236 KB Output is correct
53 Correct 8 ms 1108 KB Output is correct
54 Correct 14 ms 1264 KB Output is correct
55 Correct 21 ms 1268 KB Output is correct
56 Correct 12 ms 1300 KB Output is correct
57 Correct 66 ms 8044 KB Output is correct
58 Correct 70 ms 8860 KB Output is correct
59 Correct 81 ms 10140 KB Output is correct
60 Correct 188 ms 10084 KB Output is correct
61 Correct 191 ms 10292 KB Output is correct
62 Correct 180 ms 10000 KB Output is correct
63 Correct 614 ms 9568 KB Output is correct
64 Correct 596 ms 9696 KB Output is correct
65 Correct 607 ms 9380 KB Output is correct
66 Correct 91 ms 9672 KB Output is correct
67 Correct 105 ms 12192 KB Output is correct
68 Correct 135 ms 12300 KB Output is correct
69 Correct 120 ms 12144 KB Output is correct
70 Correct 111 ms 12204 KB Output is correct
71 Correct 111 ms 12160 KB Output is correct
72 Correct 111 ms 12216 KB Output is correct
73 Correct 106 ms 12188 KB Output is correct
74 Correct 105 ms 12196 KB Output is correct
75 Correct 250 ms 34492 KB Output is correct
76 Correct 246 ms 30272 KB Output is correct
77 Correct 216 ms 25524 KB Output is correct
78 Correct 214 ms 25540 KB Output is correct
79 Correct 278 ms 23488 KB Output is correct
80 Correct 223 ms 25536 KB Output is correct
81 Correct 609 ms 27392 KB Output is correct
82 Correct 641 ms 29796 KB Output is correct
83 Correct 607 ms 29840 KB Output is correct
84 Correct 581 ms 26860 KB Output is correct
85 Correct 595 ms 29112 KB Output is correct
86 Correct 635 ms 30112 KB Output is correct
87 Correct 560 ms 26412 KB Output is correct
88 Correct 2538 ms 28056 KB Output is correct
89 Correct 2646 ms 30408 KB Output is correct
90 Correct 2568 ms 30488 KB Output is correct
91 Correct 2501 ms 30440 KB Output is correct
92 Correct 2575 ms 30748 KB Output is correct
93 Correct 569 ms 42032 KB Output is correct
94 Correct 442 ms 36556 KB Output is correct
95 Correct 569 ms 42036 KB Output is correct
96 Correct 649 ms 41612 KB Output is correct
97 Correct 513 ms 30260 KB Output is correct
98 Correct 457 ms 36916 KB Output is correct
99 Correct 615 ms 42324 KB Output is correct
100 Correct 545 ms 41964 KB Output is correct
101 Correct 497 ms 35164 KB Output is correct
102 Correct 593 ms 41632 KB Output is correct
103 Correct 515 ms 31844 KB Output is correct
104 Correct 618 ms 41892 KB Output is correct
105 Correct 328 ms 31972 KB Output is correct
106 Correct 442 ms 40384 KB Output is correct
107 Correct 450 ms 40404 KB Output is correct
108 Correct 439 ms 40404 KB Output is correct
109 Correct 439 ms 40380 KB Output is correct
110 Correct 428 ms 40388 KB Output is correct
111 Correct 435 ms 40396 KB Output is correct
112 Correct 435 ms 40360 KB Output is correct
113 Correct 450 ms 40488 KB Output is correct
114 Correct 455 ms 40360 KB Output is correct
115 Correct 457 ms 40344 KB Output is correct
116 Correct 412 ms 42084 KB Output is correct