Submission #714919

#TimeUsernameProblemLanguageResultExecution timeMemory
714919MilosMilutinovicBalloons (CEOI11_bal)C++14
20 / 100
963 ms5452 KiB
#include <bits/stdc++.h>

using i64 = long long;

const double eps = 1E-6;

double solve(double x1, double r, double x2) {
    double low = 0, high = 1.001E9, R = 0;
    while (high - low >= eps) {
        double mid = (low + high) / 2;
        double dist = std::sqrt((long double) (x1 - x2) * (x1 - x2) + (long double) (r - mid) * (r - mid));
        if (dist >= r + mid) {
            R = mid;
            low = mid;
        } else {
            high = mid;
        }
    }
    return R;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector<double> x(n), r(n);
    for (int i = 0; i < n; i++) {
        std::cin >> x[i] >> r[i];
    }

    std::vector<int> stk;
    for (int i = 0; i < n; i++) {
        double prv = 1.1E9;
        for (int j = stk.size() - 1; j >= 0; j--) {
            double nr = solve(x[stk[j]], r[stk[j]], x[i]);
            if (nr < r[i]) {
                r[i] = nr;
            } else {
                if (prv <= nr) {
                    break;
                }
                prv = nr;
            }
        }
        while (!stk.empty() && r[i] > r[stk.back()]) {
            stk.pop_back();
        }
        stk.push_back(i);
        std::cout << std::fixed << std::setprecision(5) << r[i] << "\n";
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...