# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
746207 |
2023-05-21T22:32:06 Z |
rahulverma |
Balloons (CEOI11_bal) |
Java 11 |
|
2000 ms |
29176 KB |
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
public class bal {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] coord = new int[n];
int[] maxRad = new int[n];
double[] ans = new double[n];
for(int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
coord[i] = Integer.parseInt(st.nextToken());
maxRad[i] = Integer.parseInt(st.nextToken());
}
ans[0] = maxRad[0];
Stack<Integer> stack = new Stack<Integer>();
stack.add(0); // indexes in the stack
for(int i = 1; i < n; i++) {
double pos = maxRad[i];
while(!stack.isEmpty()) {
int top = stack.peek();
pos = Math.min(pos, dist(coord[top], ans[top], coord[i]));
if(pos >= ans[top]) stack.pop();
else break;
}
pos = Math.min(pos, maxRad[i]);
ans[i] = pos;
stack.add(i);
}
for(int i = 0; i < n; i++) {
System.out.format("%.3f", (round(ans[i], 3)));
System.out.println();
}
}
public static double dist(int x1, double r1, int x2) {
double x_1 = x1;
double x_2 = x2;
return (x_1 - x_2) * (x_1 - x_2) / (4*r1);
}
private static double round(double value, int places) {
if (places < 0) throw new IllegalArgumentException();
BigDecimal bd = new BigDecimal(Double.toString(value));
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
}
/*
3
0 9
8 1
13 7
4
0 1
15 9
23 1
38 7*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
9204 KB |
10 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
9276 KB |
2 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
10308 KB |
505 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
811 ms |
21436 KB |
2000 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1859 ms |
22612 KB |
20000 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2059 ms |
29176 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2063 ms |
25352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2047 ms |
25804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2040 ms |
26440 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2060 ms |
26240 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |