답안 #474253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474253 2021-09-17T15:13:58 Z codesauce Balloons (CEOI11_bal) C++17
0 / 100
4 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpi = vector<pair<int, int>>;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define trav(a, x) for(auto& a : x)

#define pb push_back
#define mk make_pair
#define f first
#define s second
#define all(x) begin(x), end(x)

const int MAX = 2e5 + 5;
const long long INF = 1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	#ifndef ONLINE_JUDGE
		freopen("input.in", "r", stdin);
		freopen("output.out", "w", stdout);
	#endif	
	
	/*When adding a balloon to a stack, we can remove all
	 * the ballons which are smaller than this balloon.
	 * Every time you pop the top element of the stack, check
	 * if you can lower the size of the current balloon.
	 * Finally when the preceding balloon is larger than the current 
	 * balloon, again check if you can further lower the size of
	 * the balloon being added*/
	
	int n; cin >> n;
	double long x[n], r[n];
	FOR(i, 0, n) cin >> x[i] >> r[i];
	
	stack<pair<double long, double long>> st;
	double long ans[n];
	FOR(i, 0, n){
		double long r1 = r[i];
		while(!st.empty() && r1 >= st.top().f){
			double long p = (x[i] - st.top().s)*(x[i] - st.top().s);
			double long r2 = p/(4*(st.top().f));
			r1 = min(r1, r2);
			if(r1 < st.top().f) break;
			st.pop();
		}
		if(!st.empty()){
			double long p = (x[i] - st.top().s)*(x[i] - st.top().s);
			double long r2 = p/(4*(st.top().f));
			r1 = min(r1, r2);
		}
		st.push({r1, x[i]});
		ans[i] = r1;
	}
	cout << fixed << setprecision(3);
	FOR(i, 0, n) cout << ans[i] << endl;
}

Compilation message

bal.cpp: In function 'int main()':
bal.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   freopen("input.in", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bal.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   freopen("output.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Unexpected end of file - double expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - double expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - double expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 332 KB Unexpected end of file - double expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - double expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - double expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - double expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - double expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - double expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - double expected
2 Halted 0 ms 0 KB -