#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define lid id * 2 + 1
#define rid id * 2 + 2
using namespace std;
const ll mod = 1e9 + 7;
ld bestR(ld x1, ld r1, ld x2, ld r2) {
ld l = 0, r = r2 + 1;
while (l < r - 0.001) {
ld mid = (l + r) / 2;
if (sqrtl((x2 - x1) * (x2 - x1) + abs(r1 - mid) * abs(r1 - mid)) >= r1 + mid) l = mid;
else r = mid;
}
return min(r2, l);
}
int main() {
// ifstream cin("balancing.in");
// ofstream cout("balancing.out");
int n, i;
cin >> n;
vector<ld> x(n), r(n);
for (i = 0; i < n; i++) cin >> x[i] >> r[i];
vector<ld> ans(n);
stack<int> st;
ans[0] = r[0];
st.push(0);
for (i = 1; i < n; i++) {
ld res = r[i];
while (not st.empty()) {
res = min(res, bestR(x[st.top()], ans[st.top()], x[i], r[i]));
if (res > ans[st.top()]) st.pop();
else break;
}
ans[i] = res;
st.push(i);
}
for (i = 0; i < n; i++) cout << fixed << setprecision(3) << ans[i] << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
10 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
2 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
336 KB |
209th numbers differ - expected: '5.9340000000', found: '5.9360000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
336 KB |
12th numbers differ - expected: '110.0020000000', found: '110.0000000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
68 ms |
1360 KB |
57th numbers differ - expected: '152.0000000000', found: '151.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
174 ms |
3032 KB |
50th numbers differ - expected: '15349.0000000000', found: '15348.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
373 ms |
5960 KB |
48th numbers differ - expected: '7884.0000000000', found: '7883.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
421 ms |
6692 KB |
154th numbers differ - expected: '4895.0000000000', found: '4894.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
565 ms |
8860 KB |
192nd numbers differ - expected: '1669.0000000000', found: '1668.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
732 ms |
11336 KB |
44th numbers differ - expected: '2917.0000000000', found: '2916.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |