Submission #548952

# Submission time Handle Problem Language Result Execution time Memory
548952 2022-04-14T19:44:47 Z erto Balloons (CEOI11_bal) C++17
100 / 100
584 ms 6348 KB
#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<long double, long double>> s;

long double f(long double x, long double y){
    long double t1 = y * y, l=0, r=1e9, mid, ans = 1e9;
    while(r - l >= (1e-10)){
        mid = (r + l) / 2.0;
        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;
        t = h;
        while(!s.empty()){
            tie(t1, t2) = s.top();
            ans2 = f(t2, (g - t1));
            t = min(t, ans2);
            if(t2 > t)break;
            s.pop();
        }
        cout <<fixed << setprecision(6)<< 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
1 Correct 1 ms 212 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 6 ms 348 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 60 ms 488 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 148 ms 1240 KB 50000 numbers
2 Correct 154 ms 1760 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 298 ms 1820 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 342 ms 2132 KB 115362 numbers
2 Correct 341 ms 3788 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 457 ms 2340 KB 154271 numbers
2 Correct 564 ms 6348 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 584 ms 2488 KB 200000 numbers
2 Correct 569 ms 6108 KB 199945 numbers