Submission #843302

# Submission time Handle Problem Language Result Execution time Memory
843302 2023-09-03T22:09:50 Z Anthony_Liu Balloons (CEOI11_bal) C++11
100 / 100
174 ms 8788 KB
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#define f first
#define s second
#define ld long double
#define pb push_back
#define pi pair <int,int>
#define vi vector <int>
#define size(x) (int)(x).size()
#define all(x) x.begin(), x.end()
void setIO(string name = "") {
	cin.tie(0)->sync_with_stdio(0);
	if (size(name)) {
		freopen((name + ".in").c_str(), "r", stdin);
		freopen((name + ".out").c_str(), "w", stdout);
	}
}

ld r_touch(ld ax, ld ar, ld bx) {
	ld xsq = (ax - bx) * (ax - bx);
	return xsq / (4 * ar);
}

int N;
stack <pair<ld, ld>> st;

int main()
{
	setIO();
	cin >> N;
	
	//stack stores (x, r)
	for (int i = 0; i < N; i++) {
		ld x, rlimit;
		cin >> x >> rlimit;
		
		ld r = rlimit;
		while (!st.empty()) {
			ld ax = st.top().f;
			ld ar = st.top().s;
			
			ld mr = r_touch(ax, ar, x);
			r = min(mr, r);
			
			if (r > ar) st.pop();
			else break;
		}
		
		st.push({x, r});
		cout << fixed << setprecision(3) << r << '\n';
	}
	return 0;
}

Compilation message

bal.cpp: In function 'void setIO(std::string)':
bal.cpp:16:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   freopen((name + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 16 ms 588 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 41 ms 1204 KB 50000 numbers
2 Correct 42 ms 2376 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 84 ms 1616 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 100 ms 1780 KB 115362 numbers
2 Correct 93 ms 5456 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 129 ms 2420 KB 154271 numbers
2 Correct 174 ms 8788 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 166 ms 2284 KB 200000 numbers
2 Correct 154 ms 8672 KB 199945 numbers