Submission #668147

# Submission time Handle Problem Language Result Execution time Memory
668147 2022-12-03T02:22:57 Z chanhchuong123 Balloons (CEOI11_bal) C++14
100 / 100
145 ms 5388 KB
#include <bits/stdc++.h>
using namespace std;
#define task "C"
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
  	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
  	if (a < b) {a = b; return true;} return false;
}

const int N = 2e5 + 3;
int n;
stack<pair<int, double>> st;

double calc_r(int x1, double r1, int x2) {
	return 1.0 * (x2 - x1) * (x2 - x1) / (4 * r1);
}

int main() {
  	ios_base::sync_with_stdio(0);
  	cin.tie(0); cout.tie(0);

  	if (fopen(task".inp","r")) {
    	freopen(task".inp","r",stdin);
    	freopen(task".out","w",stdout);
  	}
  	
  	cin >> n;
  	cout << setprecision(3) << fixed;
  	for (int i = 1; i <= n; i++) {
  		int x, r; cin >> x >> r;
  		double ansi = r; while (st.size()) {
  			mini(ansi, calc_r(st.top().fi, st.top().se, x));
  			if (st.top().se <= ansi) st.pop(); else break;
  		}
  		st.push({x, ansi});
  		cout << ansi << '\n';
  	}
}

Compilation message

bal.cpp: In function 'int main()':
bal.cpp:29:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |      freopen(task".inp","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bal.cpp:30:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |      freopen(task".out","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 2 ms 340 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 15 ms 624 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 40 ms 1532 KB 50000 numbers
2 Correct 34 ms 1612 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 103 ms 2876 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 87 ms 3192 KB 115362 numbers
2 Correct 73 ms 3344 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 123 ms 3984 KB 154271 numbers
2 Correct 118 ms 5336 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 145 ms 4620 KB 200000 numbers
2 Correct 127 ms 5388 KB 199945 numbers