This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double;
#define int long long
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<db> x(n + 1), r(n + 1);
for(int i = 1; i <= n; i++) {
cin >> x[i] >> r[i];
}
// distance between centers of 2 balloons
// sqrt(abs(x2 - x1)**2 + abs(r2 - r1)**2)
// must be equal to (r1 + r2)
// => (x2 - x1)**2 + abs(r2 - r1)**2 == (r1 + r2)**2
// => (x2**2 + x1**2 - 2x1x2) + (r2**2 + r1**2 - 2r1r2) = r1**2 + r2**2 + 2r1r2
// => (x2 - x1)**2 = 4r1r2
// => r2 = ((x2 - x1)**2) / (4r1)
vector<db> ans(n + 1);
stack<pair<db, db>> st;
for(int i = 1; i <= n; i++) {
if(st.empty()) {
st.push({x[i], r[i]});
ans[i] = r[i];
continue;
}
while(!st.empty()) {
pair<int, int> cur = st.top();
r[i] = min(r[i], (x[i] - cur.first) * (x[i] - cur.first) / (4 * cur.second));
if(r[i] >= cur.second) st.pop();
else break;
}
st.push({x[i], r[i]});
ans[i] = r[i];
}
for(int i = 1; i <= n; i++) {
cout << fixed << setprecision(3) << ans[i] << '\n';
}
}
# | 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... |