Submission #843271

# Submission time Handle Problem Language Result Execution time Memory
843271 2023-09-03T21:04:50 Z Anthony_Liu Balloons (CEOI11_bal) C++11
20 / 100
168 ms 7044 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(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;
		}
		
		if (!st.empty())
			r = min(r, r_touch(st.top().f, st.top().s, x));
		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 0 ms 348 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 2nd numbers differ - expected: '252735385.4379999936', found: '0.9330000000', error = '252735384.5049999952'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB 506th numbers differ - expected: '365.0000000000', found: '-2481854.0649999999', error = '2482219.0649999999'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 856 KB 655th numbers differ - expected: '591.0000000000', found: '-2402336.3029999998', error = '2402927.3029999998'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 1776 KB 250th numbers differ - expected: '15134.0000000000', found: '-10429.6650000000', error = '25563.6650000000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 3668 KB 7234th numbers differ - expected: '7160.0000000000', found: '-2398141.9989999998', error = '2405301.9989999998'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 3692 KB 4643rd numbers differ - expected: '2427.0000000000', found: '-2355611.7020000000', error = '2358038.7020000000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 128 ms 5040 KB 1734th numbers differ - expected: '1856.0220000000', found: '-2324667.3859999999', error = '2326523.4079999998'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 168 ms 7044 KB 2723rd numbers differ - expected: '859.0470000000', found: '-2333711.4849999999', error = '2334570.5319999997'
2 Halted 0 ms 0 KB -