#include <bits/stdc++.h>
#define ll long long
#define db double
#define lid id * 2 + 1
#define rid id * 2 + 2
using namespace std;
const ll mod = 1e9 + 7;
db bestR(db x1, db r1, db x2, db r2) {
db l = 0, r = r2 + 1;
while (l < r - 0.001) {
db mid = (l + r) / 2;
if (sqrt((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<db> x(n), r(n);
for (i = 0; i < n; i++) cin >> x[i] >> r[i];
vector<db> ans(n);
stack<int> st;
ans[0] = r[0];
st.push(0);
for (i = 1; i < n; i++) {
db 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 |
6 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 |
61 ms |
848 KB |
57th numbers differ - expected: '152.0000000000', found: '151.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
163 ms |
1864 KB |
50th numbers differ - expected: '15349.0000000000', found: '15348.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
312 ms |
3548 KB |
48th numbers differ - expected: '7884.0000000000', found: '7883.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
349 ms |
4032 KB |
154th numbers differ - expected: '4895.0000000000', found: '4894.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
481 ms |
5408 KB |
192nd numbers differ - expected: '1669.0000000000', found: '1668.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
585 ms |
6472 KB |
44th numbers differ - expected: '2917.0000000000', found: '2916.9980000000', error = '0.0020000000' |
2 |
Halted |
0 ms |
0 KB |
- |