Submission #474254

# Submission time Handle Problem Language Result Execution time Memory
474254 2021-09-17T15:14:31 Z codesauce Balloons (CEOI11_bal) C++17
100 / 100
594 ms 12084 KB
#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 time Memory Grader output
1 Correct 1 ms 204 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 3 ms 332 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 7 ms 448 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 60 ms 1568 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 148 ms 3976 KB 50000 numbers
2 Correct 142 ms 3932 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 311 ms 6792 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 358 ms 7612 KB 115362 numbers
2 Correct 351 ms 8972 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 474 ms 9668 KB 154271 numbers
2 Correct 565 ms 11564 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 594 ms 12084 KB 200000 numbers
2 Correct 584 ms 11568 KB 199945 numbers