답안 #544190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544190 2022-04-01T09:50:40 Z amunduzbaev 원 고르기 (APIO18_circle_selection) C++17
87 / 100
3000 ms 53164 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<set<ar<int, 2>>> pp;
	vector<int> used(n), tot;
	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].insert({a[i].y, i});
		}
	};
	
	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;
		for(int j=l;j<r;j++){
			auto it = pp[j].lower_bound({lx, -1});
			vector<ar<int, 2>> er;
			while(it != pp[j].end() && (*it)[0] < rx){
				if(check((*it)[1], i)){
					er.push_back(*it);
				} it++;
			}
			
			for(auto x : er) pp[j].erase(x), used[x[1]] = i + 1;
		}
	}
	
	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 0 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 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 4 ms 1004 KB Output is correct
20 Correct 4 ms 1016 KB Output is correct
21 Correct 4 ms 980 KB Output is correct
22 Correct 6 ms 980 KB Output is correct
23 Correct 7 ms 852 KB Output is correct
24 Correct 7 ms 1236 KB Output is correct
25 Correct 6 ms 1108 KB Output is correct
26 Correct 6 ms 1068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 267 ms 39444 KB Output is correct
2 Correct 315 ms 36648 KB Output is correct
3 Correct 295 ms 37100 KB Output is correct
4 Correct 286 ms 39376 KB Output is correct
5 Correct 388 ms 35300 KB Output is correct
6 Correct 446 ms 46704 KB Output is correct
7 Correct 403 ms 40688 KB Output is correct
8 Correct 425 ms 41784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 197 ms 11592 KB Output is correct
3 Correct 808 ms 34016 KB Output is correct
4 Correct 764 ms 36088 KB Output is correct
5 Correct 873 ms 32464 KB Output is correct
6 Correct 329 ms 21828 KB Output is correct
7 Correct 118 ms 12232 KB Output is correct
8 Correct 17 ms 3160 KB Output is correct
9 Correct 942 ms 39588 KB Output is correct
10 Correct 855 ms 41012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 462 ms 38908 KB Output is correct
2 Correct 356 ms 52296 KB Output is correct
3 Correct 450 ms 37896 KB Output is correct
4 Correct 388 ms 52620 KB Output is correct
5 Correct 381 ms 53164 KB Output is correct
6 Correct 426 ms 38832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 4 ms 1004 KB Output is correct
20 Correct 4 ms 1016 KB Output is correct
21 Correct 4 ms 980 KB Output is correct
22 Correct 6 ms 980 KB Output is correct
23 Correct 7 ms 852 KB Output is correct
24 Correct 7 ms 1236 KB Output is correct
25 Correct 6 ms 1108 KB Output is correct
26 Correct 6 ms 1068 KB Output is correct
27 Correct 8 ms 1620 KB Output is correct
28 Correct 8 ms 1620 KB Output is correct
29 Correct 8 ms 1620 KB Output is correct
30 Correct 14 ms 1504 KB Output is correct
31 Correct 14 ms 1704 KB Output is correct
32 Correct 13 ms 1720 KB Output is correct
33 Correct 97 ms 13416 KB Output is correct
34 Correct 104 ms 13444 KB Output is correct
35 Correct 106 ms 12808 KB Output is correct
36 Correct 175 ms 13624 KB Output is correct
37 Correct 174 ms 14732 KB Output is correct
38 Correct 173 ms 12304 KB Output is correct
39 Correct 1290 ms 11800 KB Output is correct
40 Correct 1317 ms 13000 KB Output is correct
41 Correct 1304 ms 13016 KB Output is correct
42 Correct 122 ms 13396 KB Output is correct
43 Correct 106 ms 18976 KB Output is correct
44 Correct 113 ms 18992 KB Output is correct
45 Correct 111 ms 18944 KB Output is correct
46 Correct 111 ms 18960 KB Output is correct
47 Correct 107 ms 18956 KB Output is correct
48 Correct 109 ms 18964 KB Output is correct
49 Correct 111 ms 19004 KB Output is correct
50 Correct 114 ms 18944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 4 ms 1004 KB Output is correct
20 Correct 4 ms 1016 KB Output is correct
21 Correct 4 ms 980 KB Output is correct
22 Correct 6 ms 980 KB Output is correct
23 Correct 7 ms 852 KB Output is correct
24 Correct 7 ms 1236 KB Output is correct
25 Correct 6 ms 1108 KB Output is correct
26 Correct 6 ms 1068 KB Output is correct
27 Correct 267 ms 39444 KB Output is correct
28 Correct 315 ms 36648 KB Output is correct
29 Correct 295 ms 37100 KB Output is correct
30 Correct 286 ms 39376 KB Output is correct
31 Correct 388 ms 35300 KB Output is correct
32 Correct 446 ms 46704 KB Output is correct
33 Correct 403 ms 40688 KB Output is correct
34 Correct 425 ms 41784 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 197 ms 11592 KB Output is correct
37 Correct 808 ms 34016 KB Output is correct
38 Correct 764 ms 36088 KB Output is correct
39 Correct 873 ms 32464 KB Output is correct
40 Correct 329 ms 21828 KB Output is correct
41 Correct 118 ms 12232 KB Output is correct
42 Correct 17 ms 3160 KB Output is correct
43 Correct 942 ms 39588 KB Output is correct
44 Correct 855 ms 41012 KB Output is correct
45 Correct 462 ms 38908 KB Output is correct
46 Correct 356 ms 52296 KB Output is correct
47 Correct 450 ms 37896 KB Output is correct
48 Correct 388 ms 52620 KB Output is correct
49 Correct 381 ms 53164 KB Output is correct
50 Correct 426 ms 38832 KB Output is correct
51 Correct 8 ms 1620 KB Output is correct
52 Correct 8 ms 1620 KB Output is correct
53 Correct 8 ms 1620 KB Output is correct
54 Correct 14 ms 1504 KB Output is correct
55 Correct 14 ms 1704 KB Output is correct
56 Correct 13 ms 1720 KB Output is correct
57 Correct 97 ms 13416 KB Output is correct
58 Correct 104 ms 13444 KB Output is correct
59 Correct 106 ms 12808 KB Output is correct
60 Correct 175 ms 13624 KB Output is correct
61 Correct 174 ms 14732 KB Output is correct
62 Correct 173 ms 12304 KB Output is correct
63 Correct 1290 ms 11800 KB Output is correct
64 Correct 1317 ms 13000 KB Output is correct
65 Correct 1304 ms 13016 KB Output is correct
66 Correct 122 ms 13396 KB Output is correct
67 Correct 106 ms 18976 KB Output is correct
68 Correct 113 ms 18992 KB Output is correct
69 Correct 111 ms 18944 KB Output is correct
70 Correct 111 ms 18960 KB Output is correct
71 Correct 107 ms 18956 KB Output is correct
72 Correct 109 ms 18964 KB Output is correct
73 Correct 111 ms 19004 KB Output is correct
74 Correct 114 ms 18944 KB Output is correct
75 Correct 435 ms 48620 KB Output is correct
76 Correct 430 ms 45212 KB Output is correct
77 Correct 375 ms 50492 KB Output is correct
78 Correct 369 ms 50688 KB Output is correct
79 Correct 440 ms 42320 KB Output is correct
80 Correct 377 ms 50576 KB Output is correct
81 Correct 795 ms 42532 KB Output is correct
82 Correct 735 ms 43324 KB Output is correct
83 Correct 731 ms 43196 KB Output is correct
84 Correct 813 ms 42148 KB Output is correct
85 Correct 751 ms 44660 KB Output is correct
86 Correct 761 ms 43700 KB Output is correct
87 Correct 978 ms 41312 KB Output is correct
88 Execution timed out 3053 ms 36604 KB Time limit exceeded
89 Halted 0 ms 0 KB -