Submission #856535

# Submission time Handle Problem Language Result Execution time Memory
856535 2023-10-03T19:15:05 Z AlphaMale06 Balloons (CEOI11_bal) C++14
50 / 100
273 ms 6604 KB
#include <bits/stdc++.h>

using namespace std;

#define double long double
#define mp make_pair
#define F first
#define S second

double dist(double r1, double x1, double r2, double x2){
    return (x1-x2)*(x1-x2)+(r1-r2)*(r1-r2);
}

double bs(double lo, double hi, double xc, double rp, double xp){
    while(abs(lo-hi)>(double)0.000001){
        double s=(lo+hi)/2;
        double dist1=s+rp;
        dist1*=dist1;
        if(dist1<dist(s, xc, rp, xp)){
            lo=s;
        }
        else{
            hi=s;
        }
    }
    return lo;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int r[n];
    int x[n];
    for(int i=0; i< n; i++){
        cin >> x[i] >> r[i];
    }
    double ans[n];
    stack<pair<double, double>> st;
    for(int i=0; i< n; i++){
        if(st.empty()){
            st.push(mp(r[i], x[i]));
            ans[i]=r[i];
        }
        else{
            double lo=0; double hi=r[i];
            while(true){
                if(st.empty())break;
                hi=bs(lo, hi, x[i], st.top().F, st.top().S);
                if(hi>=st.top().F)st.pop();
                else break;
            }
            st.push(mp(hi, x[i]));
            ans[i]=hi;
        }
    }
    cout << fixed << setprecision(3);
    for(int i=0; i< n; i++){
        cout << ans[i] << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 29 ms 860 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 2140 KB 13943rd numbers differ - expected: '3589.0000000000', found: '3588.9980000000', error = '0.0020000000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 149 ms 3940 KB 7234th numbers differ - expected: '7160.0000000000', found: '7159.9950000000', error = '0.0050000000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 168 ms 4432 KB 4693rd numbers differ - expected: '5059.4220000000', found: '5059.4200000000', error = '0.0020000000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 226 ms 5456 KB 6263rd numbers differ - expected: '4771.2560000000', found: '4771.2540000000', error = '0.0020000000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 273 ms 6604 KB 4206th numbers differ - expected: '1025.3650000000', found: '1025.3630000000', error = '0.0020000000'
2 Halted 0 ms 0 KB -