This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 2e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
long double kvadrat(long double x)
{
return x*x;
}
long double solve(long double prex, long double prer, long double trx, long double mxr)
{
long double l = 0;
long double r = mxr;
while(r-l>=1e-9)
{
long double mid = (l+r)/2;
if(kvadrat(prex-trx) + kvadrat(prer-mid) < kvadrat(mid+prer))r = mid;
else l = mid;
}
return l;
}
signed main()
{
ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
int tt=1;
//cin >> tt;
while(tt--)
{
int n;
cin >> n;
vector<long double> rovi(n);
vector<long double> xovi(n);
vector<long double> rez(n, inf);
for(int i=0; i<n; i++)cin >> xovi[i] >> rovi[i];
stack<int> stekic;
for(int i=0; i<n; i++)
{
while(!stekic.empty())
{
long double prex = xovi[stekic.top()];
long double prer = rovi[stekic.top()];
long double trr = solve(prex,prer, xovi[i], rovi[i]);
rovi[i] = min(rovi[i], trr);
if(trr >= prer)stekic.pop();
else break;
}
rez[i] = rovi[i];
stekic.push(i);
}
for(int i=0; i<n; i++)cout << fixed << setprecision(3) << rez[i] << endl;
}
}
/*
3
0 9
8 1
13 7
*/
# | 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... |