Submission #699763

# Submission time Handle Problem Language Result Execution time Memory
699763 2023-02-18T01:04:42 Z tcmmichaelb139 Balloons (CEOI11_bal) C++17
100 / 100
165 ms 14888 KB
#include "bits/stdc++.h"
using namespace std;

long double dist(pair<long long, long double> a, pair<long long, long double> b) {
    return (a.first - b.first) * (a.first - b.first) / (long double)(4 * b.second);
}

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

    cout << fixed << setprecision(3);

    int n;
    cin >> n;
    vector<pair<long long, long double>> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i].first >> v[i].second;

    vector<long double> ans(n, 1e9);
    stack<pair<long long, long double>> s;
    for (int i = 0; i < n; i++) {
        if (s.size() == 0) {
            s.push(v[i]);
            ans[i] = v[i].second;
        } else {
            ans[i] = v[i].second;
            while (s.size()) {
                ans[i] = min(ans[i], dist(v[i], s.top()));
                if (ans[i] >= s.top().second)
                    s.pop();
                else
                    break;
            }
            s.push({v[i].first, ans[i]});
        }
    }
    for (auto i : ans)
        cout << i << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1364 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 44 ms 3420 KB 50000 numbers
2 Correct 53 ms 3992 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 96 ms 6056 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 110 ms 7088 KB 115362 numbers
2 Correct 96 ms 9056 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 131 ms 9124 KB 154271 numbers
2 Correct 165 ms 14872 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 164 ms 11344 KB 200000 numbers
2 Correct 160 ms 14888 KB 199945 numbers