import java.io.*;
import java.util.*;
public class bal
{
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() { // reads in the next string
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() { // reads in the next int
return Integer.parseInt(next());
}
public long nextLong() { // reads in the next long
return Long.parseLong(next());
}
public double nextDouble() { // reads in the next double
return Double.parseDouble(next());
}
}
static InputReader r = new InputReader(System.in);
static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args)
{
int n = r.nextInt();
double[] rad = new double[n];
double[] x = new double[n];
Stack<Integer> stack = new Stack<Integer>();
for (int i = 0; i < n; i ++)
{
double a = r.nextDouble();
double b = r.nextDouble();
double last = 0.0;
while (!stack.isEmpty() && (rad[stack.peek()] <= b || last <= b))
{
double ra = rad[stack.peek()];
double lo = x[stack.peek()];
b = Math.min(b, ((a-lo)*(a-lo))/(4*ra));
last = ra;
if (b >= ra)
{
stack.pop();
}
}
x[i] = a;
rad[i] = b;
stack.add(i);
}
for (int i = 0; i < n; i ++)
{
pw.println(rad[i]);
}
pw.close();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
8444 KB |
10 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
8720 KB |
2 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
8964 KB |
505 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
423 ms |
15760 KB |
2000 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
892 ms |
18680 KB |
20000 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1532 ms |
33440 KB |
50000 numbers |
2 |
Correct |
607 ms |
17276 KB |
49912 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1592 ms |
32292 KB |
100000 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1185 ms |
26976 KB |
115362 numbers |
2 |
Correct |
673 ms |
21184 KB |
119971 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1267 ms |
27388 KB |
154271 numbers |
2 |
Correct |
762 ms |
25768 KB |
200000 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1617 ms |
35464 KB |
200000 numbers |
2 |
Correct |
739 ms |
25908 KB |
199945 numbers |