Submission #843273

#TimeUsernameProblemLanguageResultExecution timeMemory
843273Anthony_LiuBalloons (CEOI11_bal)C++11
20 / 100
191 ms3920 KiB
#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(int ax, ld ar, int bx) {
	ld xsq = (ax - bx) * (ax - bx);
	return xsq / (4 * ar);
}

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

int main()
{
	setIO();
	cin >> N;
	
	//stack stores (x, r)
	for (int i = 0; i < N; i++) {
		int x, rlimit;
		cin >> x >> rlimit;
		
		ld r = rlimit;
		while (!st.empty()) {
			int 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 (stderr)

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 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...