Submission #1004526

# Submission time Handle Problem Language Result Execution time Memory
1004526 2024-06-21T09:36:24 Z Thunnus Balloons (CEOI11_bal) C++17
100 / 100
148 ms 8764 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using i64 = long long;
template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define double long double
#define sz(x) (int)(x).size()

inline double calc_radius(pair<double, double> a, double bx){ // a.fi -> a.x, a.se -> a.r
    return (a.fi - bx) * (a.fi - bx) / (4 * a.se); // comes from Pythagorean theorem
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    double x, r;
    cin >> n;
    stack<pair<double, double>> s;
    vector<double> ans(n);
    for(int i = 0; i < n; i++){
        cin >> x >> r;
        double maxr = r;
        while(!s.empty()){
            pair<double, double> prev = s.top();
            double curr = calc_radius(prev, x);
            maxr = min(maxr, curr);
            if(maxr >= prev.se)
                s.pop();
            else
                break;
        }
        s.push({x, maxr});
        ans[i] = maxr;
    }
    cout << fixed << setprecision(3);
    for(double d : ans)
        cout << d << "\n";
    return 0;
}
# 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 2 ms 348 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1172 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2620 KB 50000 numbers
2 Correct 33 ms 2392 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 71 ms 4432 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 85 ms 5084 KB 115362 numbers
2 Correct 79 ms 5344 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 122 ms 6544 KB 154271 numbers
2 Correct 136 ms 8764 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 148 ms 7852 KB 200000 numbers
2 Correct 134 ms 8748 KB 199945 numbers