# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
474253 | codesauce | Balloons (CEOI11_bal) | C++17 | 4 ms | 332 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpi = vector<pair<int, int>>;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define all(x) begin(x), end(x)
const int MAX = 2e5 + 5;
const long long INF = 1e18;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
/*When adding a balloon to a stack, we can remove all
* the ballons which are smaller than this balloon.
* Every time you pop the top element of the stack, check
* if you can lower the size of the current balloon.
* Finally when the preceding balloon is larger than the current
* balloon, again check if you can further lower the size of
* the balloon being added*/
int n; cin >> n;
double long x[n], r[n];
FOR(i, 0, n) cin >> x[i] >> r[i];
stack<pair<double long, double long>> st;
double long ans[n];
FOR(i, 0, n){
double long r1 = r[i];
while(!st.empty() && r1 >= st.top().f){
double long p = (x[i] - st.top().s)*(x[i] - st.top().s);
double long r2 = p/(4*(st.top().f));
r1 = min(r1, r2);
if(r1 < st.top().f) break;
st.pop();
}
if(!st.empty()){
double long p = (x[i] - st.top().s)*(x[i] - st.top().s);
double long r2 = p/(4*(st.top().f));
r1 = min(r1, r2);
}
st.push({r1, x[i]});
ans[i] = r1;
}
cout << fixed << setprecision(3);
FOR(i, 0, n) cout << ans[i] << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |