답안 #625353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625353 2022-08-10T06:40:06 Z BhavayGoyal Balloons (CEOI11_bal) C++14
100 / 100
159 ms 12124 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T> using oset = 
            tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define endl "\n"

const int MOD = 1e9+7;
const int inf = 1e9;
const int linf = 1e18;

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};


// -------------------------------------------------- Main Code --------------------------------------------------

double get_r(int x1, int x2, double r1) {
    return ((x2-x1)*(x2-x1))/(4*r1);
}

void sol() {
    int n; cin >> n;
    int x[n], r[n];
    for (int i = 0; i < n; i++) cin >> x[i] >> r[i];
    stack<pair<int, double>> st; // idx, radius
    vector<double> ans(n);
    for (int i = 0; i < n; i++) {
        double max_r = r[i];
        while (!st.empty()) {
            auto last = st.top();
            double new_r = get_r(last.f, x[i], last.s);
            max_r = min(max_r, new_r);
            if (max_r > last.s) st.pop();
            else break;
        }
        ans[i] = max_r;
        st.push({x[i], max_r});
    }
    for (auto i : ans) cout << fixed << setprecision(5) << i << endl;
}

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--) {
        sol();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB 10 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB 2 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB 505 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB 2000 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1128 KB 20000 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 2860 KB 50000 numbers
2 Correct 36 ms 3220 KB 49912 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 5316 KB 100000 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 6164 KB 115362 numbers
2 Correct 70 ms 7400 KB 119971 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 8012 KB 154271 numbers
2 Correct 118 ms 12124 KB 200000 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 9692 KB 200000 numbers
2 Correct 128 ms 12108 KB 199945 numbers