Submission #474254

#TimeUsernameProblemLanguageResultExecution timeMemory
474254codesauceBalloons (CEOI11_bal)C++17
100 / 100
594 ms12084 KiB
#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); /*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; }
#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...