Submission #1075249

# Submission time Handle Problem Language Result Execution time Memory
1075249 2024-08-25T21:35:41 Z MrPavlito Balloons (CEOI11_bal) C++17
50 / 100
347 ms 11348 KB
#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-6)
    {
        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
1 Correct 0 ms 348 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 4 ms 348 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 33 ms 1508 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 3160 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 183 ms 5976 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 221 ms 6916 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 279 ms 9000 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 347 ms 11348 KB 4206th numbers differ - expected: '1025.3650000000', found: '1025.3630000000', error = '0.0020000000'
2 Halted 0 ms 0 KB -