Submission #707222

# Submission time Handle Problem Language Result Execution time Memory
707222 2023-03-08T15:36:37 Z therealpain Balloons (CEOI11_bal) C++17
100 / 100
201 ms 10136 KB
#include <bits/stdc++.h> 
#define fi first 
#define se second
#define mp make_pair
#define getbit(x, i) (((x) >> (i)) & 1)
#define all(x) x.begin(), x.end()
#define SQR(x) (x) * (x)
#define TASK ""
 
using namespace std;
 
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}
 
const long long inf = 1e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 7;

stack <pair <double, double>> st;
double x[N], r[N], ans[N];
int n;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;

	auto calc_r = [&](const pair <double, double> &a, const double &bx) {
		return SQR(a.first - bx) / (4 * a.second);
	};

	for (int i = 1; i <= n; ++i) {
		cin >> x[i] >> r[i];
		double max_r = r[i];
		while (st.size()) {
			pair <double, double> last = st.top();
			double cur = calc_r(st.top(), x[i]);

			max_r = min(max_r, cur);

			if (max_r >= last.second) {
				st.pop();
				continue;
			} else break;

		}
		st.emplace(x[i], max_r);
		ans[i] = max_r;
	}
	cout << fixed << setprecision(3);
	for (int i = 1; i <= n; ++i) cout << ans[i] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 3 ms 388 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1112 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 50 ms 2764 KB 50000 numbers
2 Correct 50 ms 2724 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 98 ms 5076 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 144 ms 5836 KB 115362 numbers
2 Correct 120 ms 6200 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 159 ms 7656 KB 154271 numbers
2 Correct 181 ms 10128 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 201 ms 9336 KB 200000 numbers
2 Correct 188 ms 10136 KB 199945 numbers