답안 #732747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
732747 2023-04-29T08:56:56 Z minhcool 원 고르기 (APIO18_circle_selection) C++17
87 / 100
3000 ms 81968 KB
#include<bits/stdc++.h>
using namespace std;
 
//#define int long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 3e5 + 5;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
int n, x[N], y[N], r[N];
 
int ans[N];
 
bool out[N];
 
unordered_map<int, int> mp;
vector<ii> vc[N];
 
bool ck(int i, int j){
//	cout << i << " " << j << "\n";
	long long dist = (1LL * ((long long)x[i] - x[j]) * ((long long)x[i] - x[j]) + 1LL * ((long long)y[i] - y[j]) * ((long long)y[i] - y[j]));
	long long rd = 1LL * ((long long)r[i] + r[j]) * ((long long)r[i] + r[j]);
	return (dist <= rd);
}
 
void process(){
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> r[i];
	set<ii> rem;
	for(int i = 1; i <= n; i++) rem.insert({-r[i], i});
	bool chk = 1;
	for(int i = 1; i <= n; i++) chk &= (r[i] == 1);
	if(chk){
		for(int i = 1; i <= n; i++) cout << i << " ";
		cout << "\n";
		exit(0);
	}
	for(int i = 30; i >= 0; i--){// executing with radius (1LL << (i - 1)) to (1LL << i)
		int rad = (1LL << i);
		mp.clear();
		for(int j = 1; j <= n; j++) vc[j].clear();
		vector<int> diff;
		for(int j = 1; j <= n; j++) if(!out[j]) diff.pb(x[j] / rad);
		sort(diff.begin(), diff.end());
		diff.resize(unique(diff.begin(), diff.end()) - diff.begin());
		for(int j = 0; j < diff.size(); j++) mp[diff[j]] = j + 1;
		for(int j = 1; j <= n; j++){
			if(!out[j]){
				//cout << "OK " << rad << " " << j << " " << x[j]/rad << " " << y[j] << "\n";
				vc[mp[x[j]/rad]].pb({y[j], j});
			}
		}
		for(int j = 1; j <= n; j++) sort(vc[j].begin(), vc[j].end());
		while(!rem.empty() && -((*rem.begin()).fi) >= (1LL << (i - 1))){
			int ind = (*rem.begin()).se;
		//	cout << rad << " " << ind << "\n";
			assert(!out[ind]);
			out[ind] = 1;
			ans[ind] = ind;
			rem.erase({-r[ind], ind});
			for(int i2 = x[ind]/rad - 5; i2 <= x[ind]/rad + 5; i2++){
				if(mp.find(i2) == mp.end()) continue;
				int temp = mp[i2];
				long long lee = (y[ind]/rad) - 5, rii = (y[ind] / rad) + 5;
			//	cout << 
				lee *= (long long)rad, rii *= (long long)rad;
				lee = max(lee, (long long)-1e9);
				rii = min(rii, (long long)1e9);
				int le = lee, ri = rii;
			//	cout << le << " " << ri << "\n";
				vector<ii>::iterator it = lower_bound(vc[temp].begin(), vc[temp].end(), make_pair(le, -oo));
				for(; it != vc[temp].end(); it++){
					if((*it).fi > ri) break;
					if(out[(*it).se]) continue;
					if(ck(ind, (*it).se)){
						//cout << ind << " " << (*it).se << "\n";
						ans[(*it).se] = ind;
						rem.erase({-r[(*it).se], (*it).se});
						out[(*it).se] = 1;
					}
				}
			}
		}
	}
	for(int i = 1; i <= n; i++) if(!ans[i]) ans[i] = i;
	for(int i = 1; i <= n; i++) cout << ans[i] << " ";
	cout << "\n";
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    process();
}

Compilation message

circle_selection.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   16 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
circle_selection.cpp: In function 'void process()':
circle_selection.cpp:54:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int j = 0; j < diff.size(); j++) mp[diff[j]] = j + 1;
      |                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7392 KB Output is correct
2 Correct 5 ms 7380 KB Output is correct
3 Correct 4 ms 7348 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 5 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 5 ms 7380 KB Output is correct
17 Correct 5 ms 7380 KB Output is correct
18 Correct 5 ms 7380 KB Output is correct
19 Correct 8 ms 7828 KB Output is correct
20 Correct 8 ms 7764 KB Output is correct
21 Correct 8 ms 7764 KB Output is correct
22 Correct 18 ms 8264 KB Output is correct
23 Correct 19 ms 8012 KB Output is correct
24 Correct 21 ms 8260 KB Output is correct
25 Correct 21 ms 8340 KB Output is correct
26 Correct 20 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 461 ms 32016 KB Output is correct
2 Correct 518 ms 36800 KB Output is correct
3 Correct 461 ms 36724 KB Output is correct
4 Correct 432 ms 31056 KB Output is correct
5 Correct 1116 ms 49968 KB Output is correct
6 Correct 1497 ms 69856 KB Output is correct
7 Correct 1137 ms 53308 KB Output is correct
8 Correct 1212 ms 62148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 365 ms 22136 KB Output is correct
3 Correct 1480 ms 59452 KB Output is correct
4 Correct 1491 ms 59604 KB Output is correct
5 Correct 1335 ms 52952 KB Output is correct
6 Correct 587 ms 32164 KB Output is correct
7 Correct 286 ms 20528 KB Output is correct
8 Correct 58 ms 10476 KB Output is correct
9 Correct 1538 ms 59280 KB Output is correct
10 Correct 1273 ms 50256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1352 ms 59984 KB Output is correct
2 Correct 154 ms 26872 KB Output is correct
3 Correct 923 ms 42332 KB Output is correct
4 Correct 1871 ms 73480 KB Output is correct
5 Correct 2057 ms 81760 KB Output is correct
6 Correct 903 ms 42772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7392 KB Output is correct
2 Correct 5 ms 7380 KB Output is correct
3 Correct 4 ms 7348 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 5 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 5 ms 7380 KB Output is correct
17 Correct 5 ms 7380 KB Output is correct
18 Correct 5 ms 7380 KB Output is correct
19 Correct 8 ms 7828 KB Output is correct
20 Correct 8 ms 7764 KB Output is correct
21 Correct 8 ms 7764 KB Output is correct
22 Correct 18 ms 8264 KB Output is correct
23 Correct 19 ms 8012 KB Output is correct
24 Correct 21 ms 8260 KB Output is correct
25 Correct 21 ms 8340 KB Output is correct
26 Correct 20 ms 8276 KB Output is correct
27 Correct 13 ms 8348 KB Output is correct
28 Correct 14 ms 8276 KB Output is correct
29 Correct 15 ms 8276 KB Output is correct
30 Correct 36 ms 8840 KB Output is correct
31 Correct 36 ms 9340 KB Output is correct
32 Correct 36 ms 9204 KB Output is correct
33 Correct 114 ms 15192 KB Output is correct
34 Correct 145 ms 15192 KB Output is correct
35 Correct 142 ms 17040 KB Output is correct
36 Correct 420 ms 26092 KB Output is correct
37 Correct 434 ms 25344 KB Output is correct
38 Correct 400 ms 23976 KB Output is correct
39 Correct 615 ms 20492 KB Output is correct
40 Correct 605 ms 20556 KB Output is correct
41 Correct 601 ms 20620 KB Output is correct
42 Correct 431 ms 19512 KB Output is correct
43 Correct 533 ms 31720 KB Output is correct
44 Correct 512 ms 31660 KB Output is correct
45 Correct 533 ms 31656 KB Output is correct
46 Correct 512 ms 31804 KB Output is correct
47 Correct 535 ms 31832 KB Output is correct
48 Correct 528 ms 31708 KB Output is correct
49 Correct 543 ms 31624 KB Output is correct
50 Correct 542 ms 31708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7392 KB Output is correct
2 Correct 5 ms 7380 KB Output is correct
3 Correct 4 ms 7348 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 5 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 5 ms 7380 KB Output is correct
17 Correct 5 ms 7380 KB Output is correct
18 Correct 5 ms 7380 KB Output is correct
19 Correct 8 ms 7828 KB Output is correct
20 Correct 8 ms 7764 KB Output is correct
21 Correct 8 ms 7764 KB Output is correct
22 Correct 18 ms 8264 KB Output is correct
23 Correct 19 ms 8012 KB Output is correct
24 Correct 21 ms 8260 KB Output is correct
25 Correct 21 ms 8340 KB Output is correct
26 Correct 20 ms 8276 KB Output is correct
27 Correct 461 ms 32016 KB Output is correct
28 Correct 518 ms 36800 KB Output is correct
29 Correct 461 ms 36724 KB Output is correct
30 Correct 432 ms 31056 KB Output is correct
31 Correct 1116 ms 49968 KB Output is correct
32 Correct 1497 ms 69856 KB Output is correct
33 Correct 1137 ms 53308 KB Output is correct
34 Correct 1212 ms 62148 KB Output is correct
35 Correct 3 ms 7380 KB Output is correct
36 Correct 365 ms 22136 KB Output is correct
37 Correct 1480 ms 59452 KB Output is correct
38 Correct 1491 ms 59604 KB Output is correct
39 Correct 1335 ms 52952 KB Output is correct
40 Correct 587 ms 32164 KB Output is correct
41 Correct 286 ms 20528 KB Output is correct
42 Correct 58 ms 10476 KB Output is correct
43 Correct 1538 ms 59280 KB Output is correct
44 Correct 1273 ms 50256 KB Output is correct
45 Correct 1352 ms 59984 KB Output is correct
46 Correct 154 ms 26872 KB Output is correct
47 Correct 923 ms 42332 KB Output is correct
48 Correct 1871 ms 73480 KB Output is correct
49 Correct 2057 ms 81760 KB Output is correct
50 Correct 903 ms 42772 KB Output is correct
51 Correct 13 ms 8348 KB Output is correct
52 Correct 14 ms 8276 KB Output is correct
53 Correct 15 ms 8276 KB Output is correct
54 Correct 36 ms 8840 KB Output is correct
55 Correct 36 ms 9340 KB Output is correct
56 Correct 36 ms 9204 KB Output is correct
57 Correct 114 ms 15192 KB Output is correct
58 Correct 145 ms 15192 KB Output is correct
59 Correct 142 ms 17040 KB Output is correct
60 Correct 420 ms 26092 KB Output is correct
61 Correct 434 ms 25344 KB Output is correct
62 Correct 400 ms 23976 KB Output is correct
63 Correct 615 ms 20492 KB Output is correct
64 Correct 605 ms 20556 KB Output is correct
65 Correct 601 ms 20620 KB Output is correct
66 Correct 431 ms 19512 KB Output is correct
67 Correct 533 ms 31720 KB Output is correct
68 Correct 512 ms 31660 KB Output is correct
69 Correct 533 ms 31656 KB Output is correct
70 Correct 512 ms 31804 KB Output is correct
71 Correct 535 ms 31832 KB Output is correct
72 Correct 528 ms 31708 KB Output is correct
73 Correct 543 ms 31624 KB Output is correct
74 Correct 542 ms 31708 KB Output is correct
75 Correct 581 ms 34880 KB Output is correct
76 Correct 645 ms 36212 KB Output is correct
77 Correct 632 ms 32096 KB Output is correct
78 Correct 513 ms 30868 KB Output is correct
79 Correct 744 ms 36220 KB Output is correct
80 Correct 504 ms 30624 KB Output is correct
81 Correct 1636 ms 61068 KB Output is correct
82 Correct 1565 ms 57664 KB Output is correct
83 Correct 1605 ms 64300 KB Output is correct
84 Correct 1528 ms 59332 KB Output is correct
85 Correct 1593 ms 59748 KB Output is correct
86 Correct 1588 ms 59164 KB Output is correct
87 Correct 1515 ms 47872 KB Output is correct
88 Correct 2070 ms 50292 KB Output is correct
89 Correct 2085 ms 50000 KB Output is correct
90 Correct 2069 ms 49864 KB Output is correct
91 Correct 2127 ms 49908 KB Output is correct
92 Correct 2102 ms 49960 KB Output is correct
93 Correct 2550 ms 81728 KB Output is correct
94 Correct 1527 ms 33144 KB Output is correct
95 Correct 2723 ms 81968 KB Output is correct
96 Correct 2427 ms 80656 KB Output is correct
97 Correct 1762 ms 41144 KB Output is correct
98 Correct 1797 ms 64776 KB Output is correct
99 Correct 2760 ms 81676 KB Output is correct
100 Execution timed out 3079 ms 75804 KB Time limit exceeded
101 Halted 0 ms 0 KB -