Submission #115342

# Submission time Handle Problem Language Result Execution time Memory
115342 2019-06-06T18:06:30 Z model_code Balloons (CEOI11_bal) C++17
100 / 100
145 ms 1912 KB
/* Model solution for the task BAL (Balloons)
 * Author: Jakub Pachocki
 * O(n) time solution
 */

#include <cstdio>
#include <algorithm>

using namespace std;

struct Balloon {
	int x;
	long double radius;
};

long double sq(long double x) {
	return x * x;
}

Balloon s[200000];
int ss;

int n;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int pos;
		scanf("%d", &pos);
		int size;
		scanf("%d", &size);
		long double maxRadius = size;
		while (ss > 0) {
			long double c = sq(s[ss - 1].x - pos);
			maxRadius = min(maxRadius, c / (4 * s[ss - 1].radius));
			if (maxRadius > s[ss - 1].radius - 1e-10)
				--ss;
			else
				break;
		}
		printf("%.3Lf\n", maxRadius);
		s[ss].x = pos;
		s[ss].radius = maxRadius;
		++ss;
	}
}

Compilation message

bal.cpp: In function 'int main()':
bal.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
bal.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &pos);
   ~~~~~^~~~~~~~~~~~
bal.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &size);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 15 ms 492 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 36 ms 1020 KB 50000 numbers
2 Correct 28 ms 604 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 77 ms 1440 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 88 ms 1656 KB 115362 numbers
2 Correct 65 ms 996 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 123 ms 1904 KB 154271 numbers
2 Correct 108 ms 1500 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 145 ms 1912 KB 200000 numbers
2 Correct 108 ms 1544 KB 199945 numbers