Submission #1275281

#TimeUsernameProblemLanguageResultExecution timeMemory
1275281sm.22Balloons (CEOI11_bal)C++20
100 / 100
106 ms6684 KiB
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
 
#define watch(x)        cerr << "\n" << (#x) << " is " << (x) << "\n";
#define int             long long 
#define ffor(i, a, b)   for(int i=a;i<b;i++)
#define rfor(i, a, b)   for(int i=a-1;i>=b;i--)
#define all(v)          v.begin(), v.end()
#define rall(v)         v.rbegin(), v.rend()
#define pb              push_back
#define fi              first
#define se              second
#define pii             pair<int, int>
#define vi              vector<int> 
#define vvi             vector<vi> 
#define show(a)         for(auto e : a) {cout<<e<<" ";} cout<<"\n"; 
#define pr(a, b, c)     ffor(i, b, c) {cout<<a[i]<<" ";} cout<<"\n";
#define cerr            if(false)cerr
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 10; 
int Mod = 1e9 + 7, INF = 1e18, BASE = 7, Block = 555;

double f(double x, double y, double z) {
        return (x - y) * (x - y) / (4 * z); 
}
void solve() {

        int n; cin>>n; 
        double x[n], r[n]; 
        ffor(i, 0, n) cin>>x[i]>>r[i]; 

        stack<int> stk; stk.push(0); 
        double ans[n]; ans[0] = r[0]; 

        // elements of the stack has to be in decreasing order 

        ffor(i, 1, n) {

                double rj = r[i]; 

                while(stk.size()) {
                        int idx = stk.top(); 

                        rj = min(f(x[idx], x[i], ans[idx]), rj);
                        // double rj = (x[idx] - x[i]) * (x[idx] - x[i]); 
                        // rj /= 4 * ans[idx]; 
                        // rj = min(rj, static_cast<double>(r[i])); 

                        if(rj >= ans[idx]) {
                                stk.pop(); 
                        } else {
                                break; 
                        }
                }

                ans[i] = rj; 
                // if(stk.empty()) ans[i] = r[i]; 
                stk.push(i); 
        }

        ffor(i, 0, n) cout<<ans[i]<<"\n"; 

}

signed main() { 
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL); 
        int t = 1; //cin>>t; 

        cout<<fixed<<setprecision(3); 

        while(t--) solve();
        return 0; 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...