Submission #1330370

#TimeUsernameProblemLanguageResultExecution timeMemory
1330370randi_pavMobile (BOI12_mobile)C++20
0 / 100
945 ms48680 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, l;
    cin >> n >> l;
    vector<pair<long long, long long>> towers(n);
    for (int i = 0; i < n; i++) {
        cin >> towers[i].first >> towers[i].second;
    }
    stack<long double> st;
    stack<pair<long long, long long>> towers_;
    towers_.push(towers[0]);
    long double max_ = 0;
    for (int i = 1; i < n; i++) {
        while (!towers_.empty()) {
            pair<long long, long long> temp = towers_.top();
            long double result = (long double)towers[i].second * towers[i].second - (long double)temp.second * temp.second;
            long double result2 = towers[i].first - temp.first;
            long double result3 = towers[i].first + temp.first;
            long double final_result = (result / result2 + result3) / 2.0;

            if (st.empty() || st.top() <= final_result) {
                st.push(final_result);
                towers_.push(towers[i]);
                
                long double x = final_result;
                if(x < 0) x = 0;
                if(x > l) x = l;
                
                long double new_result = (x - towers[i].first) * (x - towers[i].first);
                long double new_result2 = (long double)towers[i].second * towers[i].second;
                max_ = max(sqrtl(new_result + new_result2), max_);
                break;
            } else {
                st.pop();
                towers_.pop();
            }
        }
    }
    
    max_ = max(max_, (long double)sqrtl((long double)towers[0].first * towers[0].first + (long double)towers[0].second * towers[0].second));
    max_ = max(max_, (long double)sqrtl((long double)(l - towers[n-1].first) * (l - towers[n-1].first) + (long double)towers[n-1].second * towers[n-1].second));

    cout << fixed << setprecision(6) << max_ << endl;

    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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...