Submission #856536

# Submission time Handle Problem Language Result Execution time Memory
856536 2023-10-03T19:16:11 Z AlphaMale06 Balloons (CEOI11_bal) C++17
90 / 100
358 ms 13424 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.00000001){
        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(4);
    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 348 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1112 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 78 ms 2220 KB 50000 numbers
2 Correct 82 ms 2892 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 165 ms 3784 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 188 ms 4432 KB 115362 numbers
2 Correct 193 ms 6404 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 255 ms 5552 KB 154271 numbers
2 Correct 358 ms 13424 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 312 ms 6816 KB 200000 numbers
2 Incorrect 321 ms 10308 KB 199941st numbers differ - expected: '80461337.7310000062', found: '80461337.7278999984', error = '0.0031000078'
3 Halted 0 ms 0 KB -