Submission #407761

# Submission time Handle Problem Language Result Execution time Memory
407761 2021-05-19T04:29:50 Z juggernaut Circle selection (APIO18_circle_selection) C++17
19 / 100
3000 ms 459476 KB
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fr first
#define sc second
struct Circle{
	int x,y,r,id;
	void read(int i){
		cin>>x>>y>>r;
		id=i;
	}
}a[300005];
bool operator<(Circle a,Circle b){
	return a.r>b.r||(a.r==b.r&&a.id<b.id);
}
typedef long long ll;
ll sq(ll x){return x*x;}
ll dist(int x,int y,int x2,int y2){return sq(x-x2)+sq(y-y2);}
bool intersect(Circle a,Circle b){
	return dist(a.x,a.y,b.x,b.y)<=sq(a.r+b.r);
}
int n;
int ans[300005];
void subtask1(){
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		if(!ans[a[i].id])for(int j=1;j<=n;j++)if(!ans[a[j].id]&&intersect(a[i],a[j]))ans[a[j].id]=a[i].id;
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);
	exit(0);
}
void subtask2(){
	set<pair<int,int>>st;
	for(int i=1;i<=n;i++){
		st.emplace(a[i].x-a[i].r,i);
		st.emplace(a[i].x+a[i].r,i);
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		if(ans[a[i].id])continue;
		while(true){
			auto it=st.lower_bound(make_pair(a[i].x-a[i].r,-2e9));
			if(it==st.end())break;
			if(it->first>a[i].x+a[i].r)break;
			st.erase(*it);
			if(ans[it->second])continue;
			ans[it->second]=a[i].id;
		}
	}
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);
	exit(0);
}
void subtask4(){
	int r=a[1].r;
	unordered_map<int,unordered_map<int,vector<int>>>mp;
	for(int i=1;i<=n;i++)mp[a[i].x/r][a[i].y/r].push_back(i);
	for(int i=1;i<=n;i++){
		if(ans[i])continue;
		int x=a[i].x/r;
		int y=a[i].y/r;
		for(int i=x-2;i<=x+2;i++)
		for(int j=y-2;j<=y+2;j++){
			for(int to:mp[i][j])if(!ans[to])ans[to]=i;
		}
	}
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);
	exit(0);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	bool _subtask2=true;
	bool _subtask4=true;
	for(int i=1;i<=n;i++){
		a[i].read(i);
		_subtask2&=(a[i].y==0);
		_subtask4&=(a[i].r==a[1].r);
	}
	if(n<=5000)subtask1();
	else if(_subtask2)subtask2();
	else if(_subtask4)subtask4();
}
/*
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
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 2 ms 316 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 368 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 5 ms 588 KB Output is correct
20 Correct 5 ms 584 KB Output is correct
21 Correct 5 ms 588 KB Output is correct
22 Correct 54 ms 532 KB Output is correct
23 Correct 68 ms 536 KB Output is correct
24 Correct 58 ms 548 KB Output is correct
25 Correct 54 ms 556 KB Output is correct
26 Correct 62 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 857 ms 37736 KB Output is correct
2 Correct 1053 ms 38056 KB Output is correct
3 Correct 1125 ms 37768 KB Output is correct
4 Correct 987 ms 38056 KB Output is correct
5 Correct 887 ms 37684 KB Output is correct
6 Correct 906 ms 37808 KB Output is correct
7 Correct 869 ms 37972 KB Output is correct
8 Correct 827 ms 37856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 42 ms 3172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3103 ms 459476 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 2 ms 316 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 368 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 5 ms 588 KB Output is correct
20 Correct 5 ms 584 KB Output is correct
21 Correct 5 ms 588 KB Output is correct
22 Correct 54 ms 532 KB Output is correct
23 Correct 68 ms 536 KB Output is correct
24 Correct 58 ms 548 KB Output is correct
25 Correct 54 ms 556 KB Output is correct
26 Correct 62 ms 540 KB Output is correct
27 Incorrect 5 ms 716 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 2 ms 316 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 368 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 5 ms 588 KB Output is correct
20 Correct 5 ms 584 KB Output is correct
21 Correct 5 ms 588 KB Output is correct
22 Correct 54 ms 532 KB Output is correct
23 Correct 68 ms 536 KB Output is correct
24 Correct 58 ms 548 KB Output is correct
25 Correct 54 ms 556 KB Output is correct
26 Correct 62 ms 540 KB Output is correct
27 Correct 857 ms 37736 KB Output is correct
28 Correct 1053 ms 38056 KB Output is correct
29 Correct 1125 ms 37768 KB Output is correct
30 Correct 987 ms 38056 KB Output is correct
31 Correct 887 ms 37684 KB Output is correct
32 Correct 906 ms 37808 KB Output is correct
33 Correct 869 ms 37972 KB Output is correct
34 Correct 827 ms 37856 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Incorrect 42 ms 3172 KB Output isn't correct
37 Halted 0 ms 0 KB -