답안 #998897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998897 2024-06-14T19:55:12 Z hippo123 Balloons (CEOI11_bal) C++17
10 / 100
626 ms 21668 KB
#include <bits/stdc++.h>
using namespace std;

#define pr pair<double, int>
#define ll long long
#define pb push_back
#define f first
#define s second
vector<double> x, r;
set<pr> xr;

bool check(double mid, set<pr>::iterator it1, set<pr>::iterator it2, int be){
	
	bool judge=false;
	
	for (auto it=it1; it!=it2; it++){
		int pos=it->s;
		double rr=(mid+r[pos])*(mid+r[pos]);
		
		double dist1=(mid-r[pos])*(mid-r[pos])+(x[be]-x[pos])*(x[be]-x[pos]);

		if(rr>=dist1){
			judge=true; break;
		}
	}
	
	return judge;
		
}
	

int main(){
	int n; cin>>n;
	x.resize(n); r.resize(n);
	for (int i=0; i<n; i++) {
		cin>>x[i]>>r[i];
		pr node={x[i]+r[i], i};
		xr.insert(node); // r value changes and this need to be update
	}

	vector<double> ans(n);
	for (int i=0; i<n; i++){
		if(i==0) {
			ans[i]=r[i]; 
			continue;
		}
		//
		pr node={x[i]-r[i], i};
		set<pr>::iterator it1=xr.lower_bound(node); // pos can only be less than or equal to i;
		node={x[i]+r[i], i};
		set<pr>::iterator it2=xr.find(node);
		

		
		if(it1==it2) {ans[i]=r[i]; continue;}
		
		double lft=0; double rht=r[i]; 
		while(rht-lft>0.00001){
			double mid=lft+(rht-lft)/2;

			if(check(mid, it1, it2, i)) {
				rht=mid;
			}
			else lft=mid;			
			
		}
		ans[i]=lft;
		
		xr.erase(node);
		node={x[i]+lft, i};
		xr.insert(node);
	}
	cout << fixed <<setprecision(3);
	for (int i=0; i<n; i++) cout<<ans[i]<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 5th numbers differ - expected: '17.1630000000', found: '4.3710000000', error = '12.7920000000'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB 2 numbers
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 604 KB 2nd numbers differ - expected: '0.0010000000', found: '3.0000000000', error = '2.9990000000'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 624 KB 3rd numbers differ - expected: '121.0000000000', found: '120.0180000000', error = '0.9820000000'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 75 ms 2396 KB 3rd numbers differ - expected: '211.0000000000', found: '210.0110000000', error = '0.9890000000'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 144 ms 5712 KB 6th numbers differ - expected: '15394.0000000000', found: '15393.0000000000', error = '1.0000000000'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 309 ms 11300 KB 3rd numbers differ - expected: '7936.0000000000', found: '6084.6240000000', error = '1851.3760000000'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 393 ms 12968 KB 6th numbers differ - expected: '5053.0000000000', found: '5052.0000000000', error = '1.0000000000'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 515 ms 17240 KB 3rd numbers differ - expected: '1872.0000000000', found: '1871.0010000000', error = '0.9990000000'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 626 ms 21668 KB 3rd numbers differ - expected: '2960.0000000000', found: '2959.0010000000', error = '0.9990000000'
2 Halted 0 ms 0 KB -