이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |