이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
/*
Circle touches $(x, 0)$ and has radius $r$. Centre of circle would be $(x, r)$.
We have a previous circle with centre $(x0, r0)$ and radius $r0$. These two circles touch if distance between centres = sum of radii.
$ \sqrt{(x - x0)^2 + (r - r0)^2} = r + r0$.
or equivalently,
$ (x - x0)^2 + (r - r0)^2 = (r + r0)^2$, or
$ (x - x0)^2 = 4*r*r0 $
Hence
$$r = \frac{(x - x_{0})^2}{4*r_0}$$
r = (x - x0)^2 / 4*r0
At any given point, we need the minimum value of $r$ considering all circles $(x0, r0)$ that came before this circle.
One thing is for sure, we need to keep a monotonic stack which stores elements in increasing order of R from the end. (Top-most element should have minimum (r, x), then next element will have greater r but lower x, and so on).
Now, check if we can make R equal to the current top element of the stack. While we can, pop the top element of the stack! Then we get the final R, and push current circle into the stack, ez.
*/
double max_radius(pair<double, int>& c, int x) {
return (c.second - x)*(c.second - x)*1.0/(4*c.first);
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<pair<int, double>> v(n);
for(int i = 0; i < n; i++) {
cin >> v[i].first >> v[i].second;
}
stack<pair<double, int>> s;
for(int i = 0; i < n; i++) {
while(!s.empty()) {
if(s.top().first > v[i].second) break;
double mx = max_radius(s.top(), v[i].first);
// cout << i << ' ' << s.top().first << ' ' << s.top().second << ' ' << mx << '\n';
if(mx >= s.top().first) s.pop();
else break;
}
double ans = v[i].second;
if(!s.empty()) ans = min(ans, max_radius(s.top(), v[i].first));
cout << fixed << setprecision(3) << ans << '\n';
s.push({ans, v[i].first});
}
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... |