#include "bits/stdc++.h"
#define int long long
#define double long double
using namespace std;
int n;
vector<int> d;
vector<double> r;
signed main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin >> n;
d.resize(n);
r.resize(n);
for (int i = 0; i < n; i++) {
cin >> d[i] >> r[i];
}
// (r_1 + r_2)^2 = (d_2 - d_1)^2 + (r_1 - r_2)^2
// r_1^2 + 2r_1r_2 + r_2^2 = (d_2 - d_1)^2 + r_1^2 - 2r_1r_2 + r_2^2
// 4r_1_r_2 = (d_2 - d_1)^2
// r_2 = (d_2 - d_1)^2 / 4r_1
// Consider balloon a and b (a < b), if r_a <= r_b,
// balloon b blocks balloon a completely, when there is a new balloon after b
// we do not have to check balloon a
stack<int> mono;
for (int i = 0; i < n; i++) {
double size = r[i];
while (!mono.empty()) {
int j = mono.top();
size = min(size, (d[i] - d[j]) * (d[i] - d[j]) / 4.l / r[j]);
if (size >= r[j]) // balloon j does not 'block' balloon i completely, need to check larger balloon before j
mono.pop();
else break;
}
mono.push(i);
r[i] = size;
cout << fixed << setprecision(3) << size << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |