Submission #648772

# Submission time Handle Problem Language Result Execution time Memory
648772 2022-10-08T08:10:42 Z wyhong3103 Balloons (CEOI11_bal) C++14
100 / 100
1675 ms 15288 KB
#include <bits/stdc++.h>
#define all(x) begin(x),end(x)
#define fir first
#define sec second
#define sz(x) x.size()
#define pb push_back
 
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using db = double;
using ldb = long double;
using pldb = pair<ldb, ldb>;
using pdb = pair<db,db>;
using pll = pair<ll,ll>;
using vll = vector<ll>;
const double EPS = (1e-6);
 
void setio(string s){
    freopen((s + ".in").c_str(),"r",stdin);
    freopen((s + ".out").c_str(),"w",stdout);
}

ldb dist(pldb a, pldb b){
    return hypot(abs(a.fir-b.fir), abs(a.sec-b.sec));
}

void solve(){
    int n;
    cin >> n;

    vector<pldb> a(n);
    for(auto& i : a) cin >> i.fir >> i.sec;

    vector<ldb> res(n);

    //{loc, radius}, monotonic radius
    stack<pldb> s;
    

    for(int i{}; i < n; i++){
        ldb cur_hi = a[i].sec;
        while (!s.empty()){
            ldb lo = 0, hi = cur_hi;
            for(int j{}; j < 50; j++){
                ldb mid = lo + (hi-lo)/2; 
                if (dist(s.top(), {a[i].fir, mid}) > mid+s.top().sec) lo = mid;
                else hi = mid;
            }
            cur_hi = lo;
            if (lo > s.top().sec){
                s.pop(); 
            }else break;
        }

        res[i] = cur_hi;
        s.push({a[i].fir, cur_hi});
    }
    cout << setprecision(8) << fixed;
    for(auto& i : res) cout << i << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    while(t--){
        solve();
    }
    return 0;
}


Compilation message

bal.cpp: In function 'void setio(std::string)':
bal.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen((s + ".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bal.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen((s + ".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 5 ms 356 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 19 ms 436 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 176 ms 1412 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 421 ms 3804 KB 50000 numbers
2 Correct 425 ms 3232 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 856 ms 6604 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 975 ms 7596 KB 115362 numbers
2 Correct 1054 ms 7296 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 1308 ms 9888 KB 154271 numbers
2 Correct 1662 ms 15288 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 1675 ms 12380 KB 200000 numbers
2 Correct 1668 ms 11948 KB 199945 numbers