#include <bits/stdc++.h>
using namespace std;
#define double long double
#define mp make_pair
#define F first
#define S second
double dist(double r1, double x1, double r2, double x2){
return (x1-x2)*(x1-x2)+(r1-r2)*(r1-r2);
}
double bs(double lo, double hi, double xc, double rp, double xp){
while(abs(lo-hi)>0.00001){
double s=(lo+hi)/2;
double dist1=s+rp;
dist1*=dist1;
if(dist1<dist(s, xc, rp, xp)){
lo=s;
}
else{
hi=s;
}
}
return lo;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int r[n];
int x[n];
for(int i=0; i< n; i++){
cin >> x[i] >> r[i];
}
double ans[n];
stack<pair<double, double>> st;
for(int i=0; i< n; i++){
if(st.empty()){
st.push(mp(r[i], x[i]));
ans[i]=r[i];
}
else{
double lo=0; double hi=r[i];
while(true){
if(st.empty())break;
hi=bs(lo, hi, x[i], st.top().F, st.top().S);
if(hi>=st.top().F)st.pop();
else break;
}
st.push(mp(hi, x[i]));
ans[i]=hi;
}
}
cout << fixed << setprecision(3);
for(int i=0; i< n; i++){
cout << ans[i] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
10 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
2 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
505 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
348 KB |
1053rd numbers differ - expected: '335.0000000000', found: '334.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
1472 KB |
655th numbers differ - expected: '591.0000000000', found: '590.9970000000', error = '0.0030000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
2864 KB |
13943rd numbers differ - expected: '3589.0000000000', found: '3588.9810000000', error = '0.0190000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
141 ms |
5228 KB |
7234th numbers differ - expected: '7160.0000000000', found: '7159.9630000000', error = '0.0370000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
163 ms |
5972 KB |
4643rd numbers differ - expected: '2427.0000000000', found: '2426.9820000000', error = '0.0180000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
213 ms |
7844 KB |
1734th numbers differ - expected: '1856.0220000000', found: '1856.0130000000', error = '0.0090000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
253 ms |
9484 KB |
2723rd numbers differ - expected: '859.0470000000', found: '859.0450000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |