Submission #941155

# Submission time Handle Problem Language Result Execution time Memory
941155 2024-03-08T08:16:40 Z agawron Balloons (CEOI11_bal) C++14
100 / 100
114 ms 8576 KB
#include<bits/stdc++.h>

using namespace std;
using pdd = pair <double, double>;

#define f first
#define s second

constexpr int MAX_N = 2e5 + 5;

double calc_r(pdd last, double cord){
    return (last.f - cord) * (last.f - cord)/(4 * last.s);
}

int n;
int x[MAX_N], r[MAX_N];
double ans[MAX_N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> x[i] >> r[i];
    }

    stack <pdd> st;

    for(int i = 0; i < n; i++){

        double max_r = r[i];

        while(st.size() > 0){
            pdd last = st.top();

            double to_last = calc_r(last, x[i]);

            max_r = min(max_r, to_last);

            if(last.s > max_r) break;
            else{
                st.pop();
                continue;
            }
        }

        st.push({x[i], max_r});

        ans[i] = max_r;
    }

    cout << fixed << setprecision(3);

    for(int i = 0; i < n; i++){
        cout << ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2552 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2908 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 29 ms 3320 KB 50000 numbers
2 Correct 24 ms 3192 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 58 ms 3924 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 66 ms 4176 KB 115362 numbers
2 Correct 59 ms 6128 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 88 ms 4720 KB 154271 numbers
2 Correct 97 ms 8532 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 114 ms 4944 KB 200000 numbers
2 Correct 99 ms 8576 KB 199945 numbers