Submission #729865

# Submission time Handle Problem Language Result Execution time Memory
729865 2023-04-24T18:23:52 Z saken03 Balloons (CEOI11_bal) C++17
100 / 100
223 ms 6976 KB
#include<bits/stdc++.h>

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

typedef long long ll;

using namespace std;

void setIO(string name = "") {
	ios::sync_with_stdio(0);
	cin.tie(0);
	if (!name.empty()) {
		freopen((name + ".in").c_str(), "r", stdin);
		freopen((name + ".out").c_str(), "w", stdout);
	}
}

double calc_r(pair<double, double> a, double bx) {
	return (a.f - bx) * (a.f - bx) / (4 * a.s);
}

void solve() {        
	int n;
	cin >> n;

	vector<double> final_radius(n);
	stack<pair<double, double>> to_check;

	for (int i = 0; i < n; i++) {
		double x, r;
		cin >> x >> r;

		double max_r = r;

		while (!to_check.empty()) {
			pair<double, double> last = to_check.top();
			double to_last_r = calc_r(last, x);
			max_r = min(max_r, to_last_r);
			if (max_r >= last.s) {
				to_check.pop();
				continue;
			}
			else break;
		}
		to_check.push({x, max_r});
		final_radius[i] = max_r;
	}
	cout << fixed << setprecision(3);
	for (double &r : final_radius) cout << r << '\n';
}

int main() {
	setIO("");
	solve();
	return 0;
}   

Compilation message

bal.cpp: In function 'void setIO(std::string)':
bal.cpp:17:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   freopen((name + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bal.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   freopen((name + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 21 ms 888 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 58 ms 1972 KB 50000 numbers
2 Correct 54 ms 1992 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 110 ms 3504 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 130 ms 4064 KB 115362 numbers
2 Correct 122 ms 4396 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 175 ms 5188 KB 154271 numbers
2 Correct 222 ms 6976 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 215 ms 6128 KB 200000 numbers
2 Correct 223 ms 6932 KB 199945 numbers