Submission #890733

# Submission time Handle Problem Language Result Execution time Memory
890733 2023-12-21T20:03:08 Z TimAni Balloons (CEOI11_bal) C++17
100 / 100
162 ms 11156 KB
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <stack>
#include <queue>
#include <cmath>
#include <array>
#include <iomanip>

using namespace std;

void setIO(string File_name) {
    cin.tie(0)->sync_with_stdio(0);
    if (File_name.size()) {
        freopen((File_name + ".in").c_str(), "r", stdin);
        freopen((File_name + ".out").c_str(), "w", stdout);
    }
}

const long double eps = 1e-9;

void sol() {
    int n; cin >> n;
    vector<pair<double, double>> v(n);
    for(int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
    
    vector<double> ans(n);
    auto radius = [&](int curr, pair<double, double> prev) -> double {
        double r = (v[curr].first - prev.first) * ((v[curr].first - prev.first)) / (4 * prev.second);
        return r;
    };
    stack<pair<double, double>> mono;
    for(int i = 0; i < n; i++){
        double R = v[i].second;
        while(!mono.empty()){
            pair<double, double> t = mono.top();
            double r = radius(i, t);
            R = min(R, r);
            if(R >= t.second){
                mono.pop();
                continue;
            }
            else break;
        }
        mono.push(make_pair(v[i].first, R));
        ans[i] = R;
    }

    for(auto el : ans){
        cout << fixed << setprecision(6) << el << ' ';
    }
}

int main() {
    setIO("");
    int T = 1;
    //cin >> T;
    while (T--) sol();
    return 0;
}

Compilation message

bal.cpp: In function 'void setIO(std::string)':
bal.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen((File_name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bal.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen((File_name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1020 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2384 KB 50000 numbers
2 Correct 37 ms 2900 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 83 ms 4000 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 98 ms 4572 KB 115362 numbers
2 Correct 92 ms 6480 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 126 ms 6004 KB 154271 numbers
2 Correct 151 ms 10876 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 162 ms 7332 KB 200000 numbers
2 Correct 153 ms 11156 KB 199945 numbers