#include <bits/stdc++.h>
using namespace std;
#define ss second
#define ff first
typedef long long ll;
typedef long double ld;
#define int ll
const int PRECISION = 3;
/*
* how long can the radius of the new balloon at position bx be
* so that it touches the ballon a, which is described by
* its x position a.first and its radius a.second
*/
double calc_r(pair<double, double> a, double bx) {
return (a.first - bx) * (a.first - bx) / (4 * a.second);
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
// the radius of each balloon after inflating
vector<double> final_radius(n);
// the balloons we should check when we add a new one
stack<pair<double, double>> to_check;
for (int i = 0; i < n; i++) {
double x, r;
cin >> x >> r;
// the maximum radius of the current balloon
double max_r = r;
/*
* as long as the stack is not empty, we want to check
* if the last balloon makes the radius of the current balloon smaller
*/
while (!to_check.empty()) {
pair<double, double> last = to_check.top();
// the radius if the current balloon touches the last balloon
double to_last_r = calc_r(last, x);
/*
* the maximum possible radius is the smaller one between current
* maximum and the maximum radius so that we touches the last
* balloon (by which we have to stop)
*/
max_r = min(max_r, to_last_r);
/*
* if current maximum radius >= radius of the last balloon, we can
* remove the last balloon since it will never be touched by any
* new balloons other than the current one
*/
if (max_r >= last.second) {
to_check.pop();
// check the next balloon saved which will possibly reduce max_r
continue;
}
/*
* otherwise, the current balloon is smaller than the last saved
* balloon and we can stop checking
*/
else {
break;
}
}
/*
* save the x coordinate and radius of the current balloon, so that
* it can be checked later when a new balloon being inflated
*/
to_check.push({x, max_r});
final_radius[i] = max_r;
}
cout << fixed << setprecision(PRECISION);
for (double &r : final_radius) { cout << r << "\n"; }
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
Correct |
1 ms |
344 KB |
2000 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
604 KB |
20000 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
1364 KB |
50000 numbers |
2 |
Correct |
28 ms |
1988 KB |
49912 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
2128 KB |
100000 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
2524 KB |
115362 numbers |
2 |
Correct |
67 ms |
4432 KB |
119971 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
2948 KB |
154271 numbers |
2 |
Correct |
124 ms |
6996 KB |
200000 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
3412 KB |
200000 numbers |
2 |
Correct |
111 ms |
6992 KB |
199945 numbers |