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>
typedef long long int ll;
#define INF (1e9 + 7)
#define INF2 (998244353)
#define N (ll)1e6+1005
using namespace std;
int n;
long double g, t, h, t1, t2, t3;
long double ans2;
stack<pair<ll, ll>> s;
long double f(long double x, long double y){
long double t1 = y * y, l=0, r=y, mid, ans = 1e9;
while(r - l >= 1e-4){
mid = (r + l) / 2;
if(t1 + (x - mid) * (x - mid) <= (mid + x) * (mid + x)){
ans = mid;
r = mid;
}
else{
l = mid;
}
}
return ans;
}
void solve(){
cin >> n;
for(int i=1; i<=n; i++){
cin >> g >> h;
if(s.empty()){
s.push({g, h});
cout << h << "\n";
}
else{
tie(t1, t2) = s.top();
ans2 = f(t2, (g - t1));
t = min(h, ans2);
if(t2 < t){
s.pop();
while(!s.empty()){
tie(t1, t2) = s.top();
ans2 = f(t2, (g - t1));
t = min(h, ans2);
if(t2 >= t)break;
s.pop();
}
cout << t << "\n";
s.push({g, t});
}
else{
cout << t<<'\n';
s.push({g, t});
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin>>T;
while (T--){
solve();
}
}
# | 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... |