message
stringlengths
2
45.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
254
108k
cluster
float64
3
3
__index_level_0__
int64
508
217k
Provide tags and a correct Python 3 solution for this coding contest problem. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398
instruction
0
82,151
3
164,302
Tags: binary search, geometry, math Correct Solution: ``` import math x1, y1, x2, y2 = map(float, input().split()[:4]) v_max, t = map(float, input().split()[:2]) vx, vy = map(float, input().split()[:2]) wx, wy = map(float, input().split()[:2]) def f(x1, y1, x2, y2, v_max, vx, vy): low = 0 high = math.hypot(x2 - x1, y2 - y1) / (v_max - math.hypot(vx, vy)) while (high - low > 10**-8): middle = (low + high) / 2.0 x = x2 + vx * middle y = y2 + vy * middle t = math.hypot(x - x1, y - y1) / v_max if t > middle: low = middle else: high = middle return (low + high) / 2.0 time = f(x1, y1, x2, y2, v_max, -vx, -vy) if time > t: time = f(x1, y1, x2 - vx * t + wx * t, y2 - vy * t + wy * t, v_max, -wx, -wy) print(time) ```
output
1
82,151
3
164,303
Provide tags and a correct Python 3 solution for this coding contest problem. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398
instruction
0
82,152
3
164,304
Tags: binary search, geometry, math Correct Solution: ``` f = lambda: map(int, input().split()) a, b, c, d = f() s, t = f() vx, vy = f() ux, uy = f() def g(m): vt = min(t, m) ut = max(0, m - t) x = c - a - ut * ux - vt * vx y = d - b - ut * uy - vt * vy return x * x + y * y > (m * s) ** 2 l, r = 0, 1e9 while r - l > 1e-6: m = (l + r) / 2 if g(m): l = m else: r = m print(r) ```
output
1
82,152
3
164,305
Provide tags and a correct Python 3 solution for this coding contest problem. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398
instruction
0
82,153
3
164,306
Tags: binary search, geometry, math Correct Solution: ``` import math x1, y1, x2, y2 = map(int, input().split(' ')[:4]) u_max, tau = map(int, input().split(' ')[:2]) vx, vy = map(int, input().split(' ')[:2]) wx, wy = map(int, input().split(' ')[:2]) A = (x2 - x1, y2 - y1) v = (-vx, -vy) w = (-wx, -wy) B = (A[0] + tau * v[0], A[1] + tau * v[1]) def solve_sqr_eq(a, b, c): d = b**2 - 4*a*c if d >= 0: return ((-b + math.sqrt(d)) / (2*a), (-b - math.sqrt(d)) / (2*a)) else: return None a = v[0]**2 + v[1]**2 - u_max**2 b = 2 * A[0] * v[0] + 2 * A[1] * v[1] c = A[0]**2 + A[1]**2 r = solve_sqr_eq(a, b, c) if r is not None: t1, t2 = r t_min = min(t1, t2) t_max = max(t1, t2) if 0 <= t_min <= tau: print(t_min) exit(0) if 0 <= t_max <= tau: print(t_max) exit(0) a = w[0]**2 + w[1]**2 - u_max**2 b = 2 * B[0] * w[0] + 2 * B[1] * w[1] - u_max**2 * 2 * tau c = B[0]**2 + B[1]**2 - u_max**2 * tau**2 r = solve_sqr_eq(a, b, c) if r is not None: t1, t2 = r t_min = min(t1, t2) t_max = max(t1, t2) if 0 <= t_min : print(t_min + tau) exit(0) if 0 <= t_max: print(t_max + tau) exit(0) ```
output
1
82,153
3
164,307
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398 Submitted Solution: ``` d = list(map(int, input().split())) V, T = map(int, input().split()) v = tuple(map(int, input().split())) w = tuple(map(int, input().split())) o = d[0:2] d = d[2:4] l, r = 0, 1000000000 for i in range(300): m, e = (l+r)/2, o[:] if m <= T: e[0] += m * v[0] e[1] += m * v[1] else: e[0] += T * v[0] e[1] += T * v[1] e[0] += (m - T) * w[0] e[1] += (m - T) * w[1] if (d[0]-e[0])*(d[0]-e[0]) + (d[1]-e[1])*(d[1]-e[1]) <= V*V*m*m: a = m r = m - 0.000001 else: l = m + 0.000001 print(a) ```
instruction
0
82,154
3
164,308
Yes
output
1
82,154
3
164,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398 Submitted Solution: ``` f = lambda: list(map(int, input().split())) abs = lambda q: q[0] * q[0] + q[1] * q[1] dot = lambda: v[0] * d[0] + v[1] * d[1] get = lambda a, b, c: (b - (b * b - a * c) ** 0.5) / a p = f() d = [p[k + 2] - p[k] for k in [0, 1]] v, t = f() s = v * v v = f() i = get(abs(v) - s, dot(), abs(d)) d = [d[k] - t * v[k] for k in (0, 1)] v = f() j = get(abs(v) - s, dot() + t * s, abs(d) - t * t * s) print(i if i < t else t + j) ```
instruction
0
82,155
3
164,310
Yes
output
1
82,155
3
164,311
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398 Submitted Solution: ``` def f(T): t1 = min(t, T) t2 = max(T - t, 0) u = [v[0] * t1 + w[0] * t2, v[1] * t1 + w[1] * t2] C = [A[0] + u[0], A[1] + u[1]] dist = ((C[0] - B[0]) ** 2 + (C[1] - B[1]) ** 2) ** 0.5 dist2 = Vmax * T return dist2 >= dist read = lambda: map(int, input().split()) A, B, v, w = [[0, 0] for i in range(4)] A[0], A[1], B[0], B[1] = read() Vmax, t = read() v[0], v[1] = read() w[0], w[1] = read() L, R = 0, 1e12 for i in range(100): M = (L + R) / 2 if f(M): R = M else: L = M ans = R print(ans) ```
instruction
0
82,156
3
164,312
Yes
output
1
82,156
3
164,313
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398 Submitted Solution: ``` #!/usr/bin/env python3 import sys from math import * def direct(d, vmax, wx, wy): #print("direct: d={}, vmax={}, wx={}, wy={}".format(d, vmax, wx, wy), file=sys.stderr) return d / (sqrt(vmax*vmax - wy*wy) + wx) def fly(d, vmax, t, vx, vy, wx, wy, delta): sx = t * (vmax * cos(delta) + vx) sy = t * (vmax * sin(delta) + vy) # Normalize sx, sy, tx, ty = 0, 0, d - sx, 0 - sy alpha = angle_to(sx, sy, tx, ty) tx, ty = rotate_point(tx, ty, -alpha) wx, wy = rotate_point(wx, wy, -alpha) d = tx result = t + direct(d, vmax, wx, wy) #print("fly: delta =", delta, " result =", result, file=sys.stderr) return result def rotate_point(x, y, alpha): newx = x * cos(alpha) - y * sin(alpha) newy = x * sin(alpha) + y * cos(alpha) return newx, newy def angle_to(sx, sy, tx, ty): dx = tx - sx dy = ty - sy return atan2(dy, dx) def angle_minus(alpha, v): alpha -= v if alpha < 0: alpha += 2 * pi return alpha def angle_plus(alpha, v): alpha += v if alpha > 2 * pi: alpha -= 2 * pi return alpha def angle_diff(alpha, beta): result = alpha - beta if result < 0: result += 2 * pi elif result > 2 * pi: result -= 2 * pi return result def main(): sx, sy, tx, ty = map(float, input().split()) vmax, t = map(float, input().split()) vx, vy = map(float, input().split()) wx, wy = map(float, input().split()) # Normalize sx, sy, tx, ty = 0, 0, tx - sx, ty - sy alpha = angle_to(sx, sy, tx, ty) tx, ty = rotate_point(tx, ty, -alpha) vx, vy = rotate_point(vx, vy, -alpha) wx, wy = rotate_point(wx, wy, -alpha) d = tx #print("after normalize: s={}, t={}, v={}, w={}".format((sx, sy), (tx, ty), (vx, vy), (wx, wy)), file=sys.stderr) tau1 = direct(d, vmax, vx, vy) if tau1 <= t: print(tau1) return # Seed binary search by finding a lower and an upper angle alpha = 0 while True: lower = angle_minus(alpha, 0.1) upper = angle_plus(alpha, 0.1) ta = fly(d, vmax, t, vx, vy, wx, wy, alpha) tl = fly(d, vmax, t, vx, vy, wx, wy, lower) tu = fly(d, vmax, t, vx, vy, wx, wy, upper) if tl > ta and tu > ta: break else: alpha = angle_plus(alpha, 0.1) # Ternary search for the precise angle for i in range(100): #print("search: upper={}, lower={}".format(upper, lower), file=sys.stderr) delta = angle_diff(upper, lower) new_low = fly(d, vmax, t, vx, vy, wx, wy, angle_plus(lower, delta / 3)) new_high = fly(d, vmax, t, vx, vy, wx, wy, angle_plus(lower, 2 * delta / 3)) if new_low < new_high: upper = angle_plus(lower, 2 * delta / 3) else: lower = angle_plus(lower, delta / 3) print(fly(d, vmax, t, vx, vy, wx, wy, upper)) if __name__ == "__main__": main() ```
instruction
0
82,157
3
164,314
Yes
output
1
82,157
3
164,315
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398 Submitted Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def give_me_fuckin_answers_bitch(x1,y1,x2,y2,vmax,a1x,a1y,a2x,a2y,mid,t): dx,dy = x2-x1,y2-y1 if mid < t: z = (dy-a1y*mid)**2+(dx-a1x*mid)**2 else: t1 = mid-t z = (dy-a1y*t-a2y*t1)**2+(dx-a1x*t-a2x*t1)**2 if z <= vmax*vmax*mid*mid: return 1 return 0 def main(): x1,y1,x2,y2 = map(int,input().split()) vmax,t = map(int,input().split()) a1x,a1y = map(int,input().split()) a2x,a2y = map(int,input().split()) hi,lo,ans = 10**5,0,10**5 for _ in range(100000): mid = (hi+lo)/2 if give_me_fuckin_answers_bitch(x1,y1,x2,y2,vmax,a1x,a1y,a2x,a2y,mid,t): hi = mid ans = mid else: lo = mid print(ans) # Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main() ```
instruction
0
82,158
3
164,316
No
output
1
82,158
3
164,317
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398 Submitted Solution: ``` d = list(map(int,input().split())) V,T = map(int,input().split()) v = tuple(map(int,input().split())) w = tuple(map(int,input().split())) o = d[0:2] d = d[2:4] l,r = 0, 1000000000 for i in range(300): m,e = (l+r)/2, o[:] if m <= T: e[0] += m * v[0] e[1] += m * v[1] else: e[0] += T * v[0] e[1] += T * v[0] e[0] += (m-T) * w[0] e[1] += (m-T) * w[1] if (d[0]-e[0])**2 + (d[1]-e[1])**2 <= (V*m)**2: a = m r = m-0.000001 else: l = m + 0.000001 print(a) ```
instruction
0
82,159
3
164,318
No
output
1
82,159
3
164,319
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398 Submitted Solution: ``` def can(c): if c > t: x = xs + x1 * t + x2 * (c - t) y = ys + y1 * t + y2 * (c - t) else: x = xs + x1 * t y = ys + y1 * t if (v * c) ** 2 >= (x0 - x) ** 2 + (y0 - y) ** 2: return 1 else: return 0 (xs, ys, x0, y0) = map(int, input().split()) (v, t) = map(int, input().split()) (x1, y1) = map(int, input().split()) (x2, y2) = map(int, input().split()) l = 0 r = 1000000000000000 for i in range(1000): m = (l + r) / 2 if can(m): r = m else: l = m print(r) ```
instruction
0
82,160
3
164,320
No
output
1
82,160
3
164,321
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2). Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed <image> meters per second. Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after <image> seconds the new position of the dirigible will be <image>. Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer. It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air. Input The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers <image> and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively. Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that <image> and <image>. Output Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 5 5 3 2 -1 -1 -1 0 Output 3.729935587093555327 Input 0 0 0 1000 100 1000 -50 0 50 0 Output 11.547005383792516398 Submitted Solution: ``` f = lambda: map(int, input().split()) a, b, c, d = f() s, t = f() vx, vy = f() ux, uy = f() def g(m): vt = min(t, m) ut = max(0, m - t) x = c - a - ut * ux - vt * vx y = d - b - ut * uy - vt * vy return x * x + y * y > (m * s) ** 2 l, r = 0, 5 while r - l > 1e-6: m = (l + r) / 2 if g(m): l = m else: r = m print(r) ```
instruction
0
82,161
3
164,322
No
output
1
82,161
3
164,323
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem Santa Claus came from the sky to JOI town this year as well. Since every house in JOI has children, this Santa Claus must give out presents to every house in JOI. However, this year the reindeer I am carrying is a little deaf and I can only get off the top of the building, so it seems that I have to devise a little route to distribute gifts to all the houses. JOI Town is divided into north, south, east and west, and each section is a house, a church, or a vacant lot. There is only one church in JOI town. According to the following rules, Santa Claus and reindeer depart from the church, give out one gift to every house, and then return to the church. * This year's reindeer is a little deaf, so it can only fly straight in either the north, south, east, or west, and cannot change direction in the air. * You can pass freely over the house where you haven't handed out the presents yet. You can get off at a house that hasn't given out presents yet. Whenever I get home, I give out presents and then take off in either direction of north, south, east or west. * At the house in JOI town, I spend Christmas night without the fireplace until Santa Claus arrives, but after Santa Claus takes off, I turn on the fireplace. When you turn on the fireplace, smoke comes out of the chimney, so you can't pass over the house where you've finished giving out presents. * You can pass freely over the church. However, since worship is held in the church, you cannot go down to the church until you have distributed all the presents. * You can pass freely over the vacant lot, but you cannot get off at the vacant lot. Create a program that asks how many directions Santa Claus and reindeer can give gifts to, given the structure of the town as input. input The input consists of multiple datasets. Each dataset is given in the following format. Each dataset has n + 1 rows. On the first line, the integer m (1 ≤ m ≤ 10) and the integer n (1 ≤ n ≤ 10) are written separated by a space. In each line from the 2nd line to the n + 1th line, m of 0, 1, or 2 are written, separated by a blank, and each represents the state of each section. If we write the i-th section from the north and the j-th section from the west as (i, j) (1 ≤ i ≤ n, 1 ≤ j ≤ m), the j-th value on the i + 1 line is If the lot (i, j) is a vacant lot, it will be 0, if it is a house, it will be 1, and if it is a church, it will be 2. The number of churches is 1, and the number of houses is 1 or more and 23 or less. However, in the input data for scoring, the number of directions to be distributed does not exceed 2000000. When both m and n are 0, it indicates the end of input. The number of data sets does not exceed 5. Input / output example Input example 3 2 1 0 1 1 0 2 3 3 1 1 1 1 0 1 1 1 2 0 0 Output example 2 6 <image> Figure: All 6 directions to the second input example (numbers indicate the order of distribution) The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. output For each dataset, an integer indicating how many directions to distribute gifts is output on one line. Example Input 3 2 1 0 1 1 0 2 3 3 1 1 1 1 0 1 1 1 2 0 0 Output 2 6 Submitted Solution: ``` def search(town, remains, i, j): if not remains: if i == church[0]: direction = 1 if j < church[1] else -1 for cj in range(j + direction, church[1], direction): if town[i][cj] == 3: return 0 return 1 elif j == church[1]: direction = 1 if i < church[0] else -1 for ci in range(i + direction, church[0], direction): if town[ci][j] == 3: return 0 return 1 return 0 counter = 0 for ci in range(i - 1, -1, -1): if town[ci][j] == 1: town[ci][j] = 3 counter += search(town, remains - 1, ci, j) town[ci][j] = 1 elif town[ci][j] == 3: break for ci in range(i + 1, n): if town[ci][j] == 1: town[ci][j] = 3 counter += search(town, remains - 1, ci, j) town[ci][j] = 1 elif town[ci][j] == 3: break for cj in range(j - 1, -1, -1): if town[i][cj] == 1: town[i][cj] = 3 counter += search(town, remains - 1, i, cj) town[i][cj] = 1 elif town[i][cj] == 3: break for cj in range(j + 1, m): if town[i][cj] == 1: town[i][cj] = 3 counter += search(town, remains - 1, i, cj) town[i][cj] = 1 elif town[i][cj] == 3: break return counter while True: m, n = map(int, input().split()) if not n: break town = [list(map(int, input().split())) for _ in range(n)] remains = 0 for i in range(n): for j in range(m): house = town[i][j] if house == 2: church = (i, j) elif house == 1: remains += 1 print(search(town, remains, *church)) ```
instruction
0
82,512
3
165,024
No
output
1
82,512
3
165,025
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem Santa Claus came from the sky to JOI town this year as well. Since every house in JOI has children, this Santa Claus must give out presents to every house in JOI. However, this year the reindeer I am carrying is a little deaf and I can only get off the top of the building, so it seems that I have to devise a little route to distribute gifts to all the houses. JOI Town is divided into north, south, east and west, and each section is a house, a church, or a vacant lot. There is only one church in JOI town. According to the following rules, Santa Claus and reindeer depart from the church, give out one gift to every house, and then return to the church. * This year's reindeer is a little deaf, so it can only fly straight in either the north, south, east, or west, and cannot change direction in the air. * You can pass freely over the house where you haven't handed out the presents yet. You can get off at a house that hasn't given out presents yet. Whenever I get home, I give out presents and then take off in either direction of north, south, east or west. * At the house in JOI town, I spend Christmas night without the fireplace until Santa Claus arrives, but after Santa Claus takes off, I turn on the fireplace. When you turn on the fireplace, smoke comes out of the chimney, so you can't pass over the house where you've finished giving out presents. * You can pass freely over the church. However, since worship is held in the church, you cannot go down to the church until you have distributed all the presents. * You can pass freely over the vacant lot, but you cannot get off at the vacant lot. Create a program that asks how many directions Santa Claus and reindeer can give gifts to, given the structure of the town as input. input The input consists of multiple datasets. Each dataset is given in the following format. Each dataset has n + 1 rows. On the first line, the integer m (1 ≤ m ≤ 10) and the integer n (1 ≤ n ≤ 10) are written separated by a space. In each line from the 2nd line to the n + 1th line, m of 0, 1, or 2 are written, separated by a blank, and each represents the state of each section. If we write the i-th section from the north and the j-th section from the west as (i, j) (1 ≤ i ≤ n, 1 ≤ j ≤ m), the j-th value on the i + 1 line is If the lot (i, j) is a vacant lot, it will be 0, if it is a house, it will be 1, and if it is a church, it will be 2. The number of churches is 1, and the number of houses is 1 or more and 23 or less. However, in the input data for scoring, the number of directions to be distributed does not exceed 2000000. When both m and n are 0, it indicates the end of input. The number of data sets does not exceed 5. Input / output example Input example 3 2 1 0 1 1 0 2 3 3 1 1 1 1 0 1 1 1 2 0 0 Output example 2 6 <image> Figure: All 6 directions to the second input example (numbers indicate the order of distribution) The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. output For each dataset, an integer indicating how many directions to distribute gifts is output on one line. Example Input 3 2 1 0 1 1 0 2 3 3 1 1 1 1 0 1 1 1 2 0 0 Output 2 6 Submitted Solution: ``` ''' 今年も JOI 町にサンタクロースが空からやってきた.JOI 町にある全ての家には子供がいるので,この サンタクロースは JOI 町の全ての家にプレゼントを配ってまわらなければならない.しかし,今年は連れ ているトナカイが少々方向音痴であり,また建物の上以外に降りることができないため,全ての家にプレゼ ントを配るためには少々道順を工夫しなければならないようだ. JOI 町は東西南北に区画整理されており,各区画は家,教会,空き地のいずれかである.JOI 町には 1 つだけ教会がある.次のルールに従い,サンタクロースとトナカイは教会から出発し,全ての家に 1 回ず つプレゼントを配った後,教会に戻る. - 今年のトナカイは少々方向音痴であるため,東西南北いずれかの方向にまっすぐ飛ぶことしかできず,空 中では方向転換できない. - まだプレゼントを配っていない家の上は自由に通過できる.まだプレゼントを配っていない家には降りる ことができる.家に降りた時は必ずプレゼントを配り,その後は東西南北いずれかの方向に飛び立つ. - JOI 町の家では,クリスマスの夜はサンタクロースが来るまでは暖炉をつけずに過ごしているが,サン タクロースが飛び立った後は暖炉をつける.暖炉をつけると煙突から煙が出るので,プレゼントを配り終 えた家の上を通過することはできない. - 教会の上は自由に通過することができる.しかし,教会では礼拝が行われているので,全てのプレゼント を配り終えるまで教会に降りることはできない. - 空き地の上は自由に通過することができるが,空き地に降りることはできない. 入力として町の構造が与えられたとき,サンタクロースとトナカイがプレゼントを配る道順が何通りあるか を求めるプログラムを作成せよ. ''' import copy dc = copy.deepcopy ans = 0 M = N = 0 def walk(field, pos_x, pos_y, direction): now_state = field[pos_y][pos_x] if now_state == 2: if sum(sum(field, [])) == 2: global ans ans += 1 return field[pos_y][pos_x] = 0 if (now_state or direction == 'r') and pos_x < M - 1: walk(dc(field), pos_x + 1, pos_y, 'r') if (now_state or direction == 'l') and 0 < pos_x: walk(dc(field), pos_x - 1, pos_y, 'l') if (now_state or direction == 'u') and 0 < pos_y: walk(dc(field), pos_x, pos_y - 1, 'u') if (now_state or direction == 'd') and pos_y < N - 1: walk(dc(field), pos_x, pos_y + 1, 'd') for e in iter(input, '0 0'): M, N = map(int, e.split()) field = [] for i in range(N): row = list(map(int, input().split())) field.append(row) if 2 in row: ch_x = row.index(2) ch_y = i if ch_x < M - 1: walk(dc(field), ch_x + 1, ch_y, 'r') if 0 < ch_x: walk(dc(field), ch_x - 1, ch_y, 'l') if 0 < ch_y: walk(dc(field), ch_x, ch_y - 1, 'u') if ch_y < N - 1: walk(dc(field), ch_x, ch_y + 1, 'd') print(ans) ```
instruction
0
82,513
3
165,026
No
output
1
82,513
3
165,027
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Piegirl found the red button. You have one last chance to change the inevitable end. The circuit under the button consists of n nodes, numbered from 0 to n - 1. In order to deactivate the button, the n nodes must be disarmed in a particular order. Node 0 must be disarmed first. After disarming node i, the next node to be disarmed must be either node (2·i) modulo n or node (2·i) + 1 modulo n. The last node to be disarmed must be node 0. Node 0 must be disarmed twice, but all other nodes must be disarmed exactly once. Your task is to find any such order and print it. If there is no such order, print -1. Input Input consists of a single integer n (2 ≤ n ≤ 105). Output Print an order in which you can to disarm all nodes. If it is impossible, print -1 instead. If there are multiple orders, print any one of them. Examples Input 2 Output 0 1 0 Input 3 Output -1 Input 4 Output 0 1 3 2 0 Input 16 Output 0 1 2 4 9 3 6 13 10 5 11 7 15 14 12 8 0 Submitted Solution: ``` n = int(input()) used = [False for i in range(n)] li = [0] i = 0 while True: if used[(i*2+1)%n]: if used[(i*2)%n]: break; else: i = (i*2)%n used[i] = True li.append(i) else: i = (i*2+1)%n used[i] = True li.append(i) if used.count(False): print(-1) else: print(' '.join(map(str, li))) ```
instruction
0
82,893
3
165,786
No
output
1
82,893
3
165,787
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests! Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives! The funny part is that these tasks would be very easy for a human to solve. The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point. Input The first line contains an integer n (2 ≤ n ≤ 10). Each of the following 4n + 1 lines contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 50), describing the coordinates of the next point. It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct. Output Print two integers — the coordinates of the point that is not on the boundary of the square. Examples Input 2 0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2 Output 1 1 Input 2 0 0 0 1 0 2 0 3 1 0 1 2 2 0 2 1 2 2 Output 0 3 Note In both examples, the square has four sides x=0, x=2, y=0, y=2. Submitted Solution: ``` n = int(input()) f = [] X = [] Y = [] for i in range(4 * n + 1): x, y = map(int, input().split()) f.append((x, y)) X.append(x) Y.append(y) l = min(X) r = max(X) d = min(Y) u = max(Y) if r - l == u - d: for i in f: if X.count(i[0]) == 1 and Y.count(i[1]) == 1: print(i[0], i[1]) exit() for i in f: if l < i[0] < r and d < i[1] < u: print(i[0], i[1]) exit() else: for i in f: if X.count(i[0]) == 1 and Y.count(i[1]) == 1: print(i[0], i[1]) exit() for i in f: if X.count(i[0]) == 1 and (i[0] == l or i[0] == r): print(i[0], i[1]) exit() elif Y.count(i[1]) == 1 and (i[1] == u or i[1] == d): print(i[0], i[1]) exit() ```
instruction
0
83,451
3
166,902
Yes
output
1
83,451
3
166,903
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests! Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives! The funny part is that these tasks would be very easy for a human to solve. The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point. Input The first line contains an integer n (2 ≤ n ≤ 10). Each of the following 4n + 1 lines contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 50), describing the coordinates of the next point. It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct. Output Print two integers — the coordinates of the point that is not on the boundary of the square. Examples Input 2 0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2 Output 1 1 Input 2 0 0 0 1 0 2 0 3 1 0 1 2 2 0 2 1 2 2 Output 0 3 Note In both examples, the square has four sides x=0, x=2, y=0, y=2. Submitted Solution: ``` import math n = int(input()) arr = [] for i in range(4*n + 1): arr.append(list(map(int,input().split()))) for g in range(len(arr)): xMin = math.inf xMax = -1* math.inf yMin = math.inf yMax = -1* math.inf fl = True for i in range(4*n + 1): if i!=g: a,b = arr[i] xMin = min(xMin,a) xMax = max(xMax, a) yMin = min(b,yMin) yMax = max(b,yMax) for i in range(4*n + 1): if i != g: if (arr[i][0] != xMax and arr[i][0] != xMin)and(arr[i][1] != yMax and arr[i][1] != yMin): fl=False break if fl: print(arr[g][0],arr[g][1]) break ```
instruction
0
83,452
3
166,904
No
output
1
83,452
3
166,905
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is the constraint on k. Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The color of one camera is red, and the other one's color is blue. Gildong is going to take videos for n days, starting from day 1 to day n. The forest can be divided into m areas, numbered from 1 to m. He'll use the cameras in the following way: * On every odd day (1-st, 3-rd, 5-th, ...), bring the red camera to the forest and record a video for 2 days. * On every even day (2-nd, 4-th, 6-th, ...), bring the blue camera to the forest and record a video for 2 days. * If he starts recording on the n-th day with one of the cameras, the camera records for only one day. Each camera can observe k consecutive areas of the forest. For example, if m=5 and k=3, he can put a camera to observe one of these three ranges of areas for two days: [1,3], [2,4], and [3,5]. Gildong got information about how many animals will be seen in each area each day. Since he would like to observe as many animals as possible, he wants you to find the best way to place the two cameras for n days. Note that if the two cameras are observing the same area on the same day, the animals observed in that area are counted only once. Input The first line contains three integers n, m, and k (1 ≤ n ≤ 50, 1 ≤ m ≤ 2 ⋅ 10^4, 1 ≤ k ≤ min(m,20)) – the number of days Gildong is going to record, the number of areas of the forest, and the range of the cameras, respectively. Next n lines contain m integers each. The j-th integer in the i+1-st line is the number of animals that can be seen on the i-th day in the j-th area. Each number of animals is between 0 and 1000, inclusive. Output Print one integer – the maximum number of animals that can be observed. Examples Input 4 5 2 0 2 1 1 0 0 0 3 1 2 1 0 4 3 1 3 3 0 0 4 Output 25 Input 3 3 1 1 2 3 4 5 6 7 8 9 Output 31 Input 3 3 2 1 2 3 4 5 6 7 8 9 Output 44 Input 3 3 3 1 2 3 4 5 6 7 8 9 Output 45 Note The optimal way to observe animals in the four examples are as follows: Example 1: <image> Example 2: <image> Example 3: <image> Example 4: <image> Submitted Solution: ``` n, m, k = map(int, input().split()) a = [] for _ in range(n): a.append(list(map(int, input().split()))) count = 0 for i in range(len(a)-1): ini, fim = 0, k-1 big_k = sum(a[i][:k]) + sum(a[i+1][:k]) cur = big_k for j in range(k, len(a[i])): big_k = big_k - a[i][j-k] - a[i+1][j-k] big_k += a[i][j] + a[i+1][j] if big_k > cur: cur = big_k ini = j-k+1 fim = j count += cur for j in range(ini, fim+1): a[i][j] = 0 a[i+1][j] = 0 last = sum(a[-1][:k]) ini = 0 fim = k-1 cur = last for j in range(k, len(a[0])): last -= a[-1][j-k] last += a[-1][j] if last > cur: cur = last ini = j-k+1 fim = j for j in range(ini, fim+1): a[-1][j] = 0 count += cur print(count) ```
instruction
0
83,521
3
167,042
No
output
1
83,521
3
167,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is the constraint on k. Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The color of one camera is red, and the other one's color is blue. Gildong is going to take videos for n days, starting from day 1 to day n. The forest can be divided into m areas, numbered from 1 to m. He'll use the cameras in the following way: * On every odd day (1-st, 3-rd, 5-th, ...), bring the red camera to the forest and record a video for 2 days. * On every even day (2-nd, 4-th, 6-th, ...), bring the blue camera to the forest and record a video for 2 days. * If he starts recording on the n-th day with one of the cameras, the camera records for only one day. Each camera can observe k consecutive areas of the forest. For example, if m=5 and k=3, he can put a camera to observe one of these three ranges of areas for two days: [1,3], [2,4], and [3,5]. Gildong got information about how many animals will be seen in each area each day. Since he would like to observe as many animals as possible, he wants you to find the best way to place the two cameras for n days. Note that if the two cameras are observing the same area on the same day, the animals observed in that area are counted only once. Input The first line contains three integers n, m, and k (1 ≤ n ≤ 50, 1 ≤ m ≤ 2 ⋅ 10^4, 1 ≤ k ≤ min(m,20)) – the number of days Gildong is going to record, the number of areas of the forest, and the range of the cameras, respectively. Next n lines contain m integers each. The j-th integer in the i+1-st line is the number of animals that can be seen on the i-th day in the j-th area. Each number of animals is between 0 and 1000, inclusive. Output Print one integer – the maximum number of animals that can be observed. Examples Input 4 5 2 0 2 1 1 0 0 0 3 1 2 1 0 4 3 1 3 3 0 0 4 Output 25 Input 3 3 1 1 2 3 4 5 6 7 8 9 Output 31 Input 3 3 2 1 2 3 4 5 6 7 8 9 Output 44 Input 3 3 3 1 2 3 4 5 6 7 8 9 Output 45 Note The optimal way to observe animals in the four examples are as follows: Example 1: <image> Example 2: <image> Example 3: <image> Example 4: <image> Submitted Solution: ``` import sys input = sys.stdin.readline n, m, k = map(int, input().split()) a = [list(map(int, input().split())) for i in range(n)] b = list(a) tmp_ans = 0 for i in range(n-1, -1, -1): if i < n-1: id = 0 tmp = sum(a[i][:k]) + sum(a[i+1][:k]) s = tmp for j in range(k, m): tmp -= a[i][j - k] + a[i+1][j-k] tmp += a[i][j] + a[i+1][j] if tmp > s: id = j - k + 1 s = tmp tmp_ans += s for j in range(id, id+k): a[i+1][j] = 0 a[i][j] = 0 else: id = 0 tmp = sum(a[i][:k]) s = tmp for j in range(k, m): tmp -= a[i][j - k] tmp += a[i][j] if tmp > s: id = j - k + 1 s = tmp for j in range(id, id+k): a[i][j] = 0 tmp_ans += s ans = tmp_ans tmp_ans = 0 a = list(b) for i in range(n-1, -1, -1): if i < n-1: id = 0 tmp = sum(a[i][:k]) + sum(a[i+1][:k]) s = tmp for j in range(k, m): tmp -= a[i][j - k] + a[i+1][j-k] tmp += a[i][j] + a[i+1][j] if tmp > s: id = j - k + 1 s = tmp tmp_ans += s for j in range(id, id+k): a[i+1][j] = 0 a[i][j] = 0 else: id = 0 tmp = sum(a[i][:k]) s = tmp for j in range(k, m): tmp -= a[i][j - k] tmp += a[i][j] if tmp > s: id = j - k + 1 s = tmp for j in range(id, id+k): a[i][j] = 0 tmp_ans += s ans = max(tmp_ans, ans) print(ans) ```
instruction
0
83,522
3
167,044
No
output
1
83,522
3
167,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is the constraint on k. Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The color of one camera is red, and the other one's color is blue. Gildong is going to take videos for n days, starting from day 1 to day n. The forest can be divided into m areas, numbered from 1 to m. He'll use the cameras in the following way: * On every odd day (1-st, 3-rd, 5-th, ...), bring the red camera to the forest and record a video for 2 days. * On every even day (2-nd, 4-th, 6-th, ...), bring the blue camera to the forest and record a video for 2 days. * If he starts recording on the n-th day with one of the cameras, the camera records for only one day. Each camera can observe k consecutive areas of the forest. For example, if m=5 and k=3, he can put a camera to observe one of these three ranges of areas for two days: [1,3], [2,4], and [3,5]. Gildong got information about how many animals will be seen in each area each day. Since he would like to observe as many animals as possible, he wants you to find the best way to place the two cameras for n days. Note that if the two cameras are observing the same area on the same day, the animals observed in that area are counted only once. Input The first line contains three integers n, m, and k (1 ≤ n ≤ 50, 1 ≤ m ≤ 2 ⋅ 10^4, 1 ≤ k ≤ min(m,20)) – the number of days Gildong is going to record, the number of areas of the forest, and the range of the cameras, respectively. Next n lines contain m integers each. The j-th integer in the i+1-st line is the number of animals that can be seen on the i-th day in the j-th area. Each number of animals is between 0 and 1000, inclusive. Output Print one integer – the maximum number of animals that can be observed. Examples Input 4 5 2 0 2 1 1 0 0 0 3 1 2 1 0 4 3 1 3 3 0 0 4 Output 25 Input 3 3 1 1 2 3 4 5 6 7 8 9 Output 31 Input 3 3 2 1 2 3 4 5 6 7 8 9 Output 44 Input 3 3 3 1 2 3 4 5 6 7 8 9 Output 45 Note The optimal way to observe animals in the four examples are as follows: Example 1: <image> Example 2: <image> Example 3: <image> Example 4: <image> Submitted Solution: ``` n, m, k = map(int, input().split()) a = [] for _ in range(n): a.append(list(map(int, input().split()))) count = 0 for i in range(len(a)-1): ini, fim = 0, k-1 big_k = sum(a[i][:k]) + sum(a[i+1][:k]) cur = big_k for j in range(k, len(a[i])): big_k = big_k - a[i][j-k] - a[i+1][j-k] big_k += a[i][j] + a[i+1][j] if big_k > cur: cur = big_k ini = j-k+1 fim = j elif big_k == cur: linha = a[i][j-k+1:j+1] cur_linha = a[i][ini:fim+1] if sum(linha) > sum(cur_linha): cur = big_k ini = j-k+1 fim = j count += cur for j in range(ini, fim+1): a[i][j] = 0 a[i+1][j] = 0 last = sum(a[-1][:k]) ini = 0 fim = k-1 cur = last for j in range(k, len(a[0])): last -= a[-1][j-k] last += a[-1][j] if last > cur: cur = last ini = j-k+1 fim = j for j in range(ini, fim+1): a[-1][j] = 0 count += cur print(count) ```
instruction
0
83,523
3
167,046
No
output
1
83,523
3
167,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is the constraint on k. Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The color of one camera is red, and the other one's color is blue. Gildong is going to take videos for n days, starting from day 1 to day n. The forest can be divided into m areas, numbered from 1 to m. He'll use the cameras in the following way: * On every odd day (1-st, 3-rd, 5-th, ...), bring the red camera to the forest and record a video for 2 days. * On every even day (2-nd, 4-th, 6-th, ...), bring the blue camera to the forest and record a video for 2 days. * If he starts recording on the n-th day with one of the cameras, the camera records for only one day. Each camera can observe k consecutive areas of the forest. For example, if m=5 and k=3, he can put a camera to observe one of these three ranges of areas for two days: [1,3], [2,4], and [3,5]. Gildong got information about how many animals will be seen in each area each day. Since he would like to observe as many animals as possible, he wants you to find the best way to place the two cameras for n days. Note that if the two cameras are observing the same area on the same day, the animals observed in that area are counted only once. Input The first line contains three integers n, m, and k (1 ≤ n ≤ 50, 1 ≤ m ≤ 2 ⋅ 10^4, 1 ≤ k ≤ min(m,20)) – the number of days Gildong is going to record, the number of areas of the forest, and the range of the cameras, respectively. Next n lines contain m integers each. The j-th integer in the i+1-st line is the number of animals that can be seen on the i-th day in the j-th area. Each number of animals is between 0 and 1000, inclusive. Output Print one integer – the maximum number of animals that can be observed. Examples Input 4 5 2 0 2 1 1 0 0 0 3 1 2 1 0 4 3 1 3 3 0 0 4 Output 25 Input 3 3 1 1 2 3 4 5 6 7 8 9 Output 31 Input 3 3 2 1 2 3 4 5 6 7 8 9 Output 44 Input 3 3 3 1 2 3 4 5 6 7 8 9 Output 45 Note The optimal way to observe animals in the four examples are as follows: Example 1: <image> Example 2: <image> Example 3: <image> Example 4: <image> Submitted Solution: ``` from bisect import bisect_left as bl from bisect import bisect_right as br import heapq import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline M = mod = 10**9 + 7 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip('\n').split()] def st():return input().rstrip('\n') def val():return int(input().rstrip('\n')) def li2():return [i for i in input().rstrip('\n').split(' ')] def li3():return [int(i) for i in input().rstrip('\n')] def givesum(l,ind,m): curr = [0 for i in range(m)] for j in range(m): curr[j] += l[ind][j] + l[ind + 1][j] return curr def givemaxindex(l,k): # print('l : ',l) ma = curr = 0 currindex = [0,k-1] for i in range(k): curr += l[i] ma = curr for i in range(k,len(l)): curr -= l[i-k] curr += l[i] if curr > ma: ma = curr currindex = [i - k + 1,i] return [currindex[0],currindex[1],ma] n,m,k = li() l = [] for i in range(n): l.append(li()) l.append([0 for i in range(m)]) tot = 0 n = len(l) for i in range(0,n-1): currl = givesum(l,i,m) ind1,ind2,su = givemaxindex(currl,k) for j in range(ind1,ind2 + 1): l[i+1][j] = 0 tot += su # print(*l,sep = '\n') # print() # print(tot) # print() # tot += su print(tot) ```
instruction
0
83,524
3
167,048
No
output
1
83,524
3
167,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds. Submitted Solution: ``` def scan_int_ln(): return [int(x) for x in input().split()] n = int(input()) m = scan_int_ln() avg = sum(m)/len(m) time = 0 m.sort() if avg == int(avg): avg = int(avg) for x in m: time += abs(avg-x) else: higher_n = sum(m) % n lower_n = n - higher_n mm = [int(avg)]*lower_n + [int(avg)+1]*higher_n for x, y in zip(m, mm): time += abs(y-x) time //= 2 print(time) ```
instruction
0
83,819
3
167,638
Yes
output
1
83,819
3
167,639
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) s = sum(a) l = s // n if s % n == 0: r = l else: r = l + 1 k1 = k2 = 0 for x in a: if x < l: k1 += l - x elif x > r: k2 += x - r print(max(k1,k2)) ```
instruction
0
83,820
3
167,640
Yes
output
1
83,820
3
167,641
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds. Submitted Solution: ``` n = int(input()) m = [int(x) for x in input().split()] avg = sum(m)//(len(m)) if avg * n == sum(m): print(sum([max(0,avg-x) for x in m])) else: x = sum([max(0,x-avg-1) for x in m]) y = sum([max(0,avg-x) for x in m]) print(max(x,y)) ```
instruction
0
83,822
3
167,644
Yes
output
1
83,822
3
167,645
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds. Submitted Solution: ``` def intavg(a): return sum(a) // len(a) def move(servers, avg, i=0, j=-1): removeleft = False if abs(servers[i] - avg) < abs(servers[j] - avg): removeleft = True amount = min(abs(servers[i] - avg), abs(servers[j] - avg)) if abs(servers[i] - servers[j]) <= 1: return 0, removeleft servers[i] += amount servers[j] -= amount # print(f"Debug {servers[i]}, {servers[j]}, amount: {amount}, average: {avg}") return amount, removeleft printstuff = False if int(input()) > 80: printstuff = True servers = [int(x) for x in input().split(' ')] if printstuff: for i in servers: print(i) avg = intavg(servers) servers.sort() seconds = 0 while len(servers) > 1: # print('\n', *servers, "is the servers\n") newseconds, removeleft = move(servers, avg) seconds += newseconds if removeleft: servers = servers[1:] else: servers = servers[:-1] print(seconds) ```
instruction
0
83,823
3
167,646
No
output
1
83,823
3
167,647
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds. Submitted Solution: ``` n = int(input()) m = list(map(int, input().split())) Sum = sum(m) mid = Sum // n if Sum % n == 0: ans = sum(abs(i - mid) for i in m) // 2 else: cntscd = Sum % n cnt = ans = 0 for i in m: if i > mid and cnt < cntscd: cnt += 1 ans += i - mid - 1 else: ans += abs(mid - i) ans = (ans + 1) // 2 print(ans) ```
instruction
0
83,824
3
167,648
No
output
1
83,824
3
167,649
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds. Submitted Solution: ``` import math n = int(input()) lst = [int(i) for i in input().split()] average = int(math.floor(sum(lst) / n)) lst = [ average - i for i in lst if i <= average ] print(sum(lst)) ```
instruction
0
83,826
3
167,652
No
output
1
83,826
3
167,653
Provide tags and a correct Python 3 solution for this coding contest problem. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040
instruction
0
83,827
3
167,654
Tags: math Correct Solution: ``` n, t = (float(x) for x in input().split()) print(n * (1.000000011 ** t)) ```
output
1
83,827
3
167,655
Provide tags and a correct Python 3 solution for this coding contest problem. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040
instruction
0
83,828
3
167,656
Tags: math Correct Solution: ``` n,m = map(int, input().split()) print(n*1.000000011**m) ```
output
1
83,828
3
167,657
Provide tags and a correct Python 3 solution for this coding contest problem. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040
instruction
0
83,829
3
167,658
Tags: math Correct Solution: ``` # print('Hello, Python!') import math INCREASE = 1.000000011 n, t = map(int, input().split(' ')) print(n*math.pow(INCREASE, t)) ```
output
1
83,829
3
167,659
Provide tags and a correct Python 3 solution for this coding contest problem. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040
instruction
0
83,830
3
167,660
Tags: math Correct Solution: ``` a=input() b=[] b=a.split() number=int(b[0]) degree=int(b[1]) res=number*1.000000011**degree print(res) ```
output
1
83,830
3
167,661
Provide tags and a correct Python 3 solution for this coding contest problem. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040
instruction
0
83,831
3
167,662
Tags: math Correct Solution: ``` import math l = input().split(" ") n = (int)(l[0]) t = (int)(l[1]) print(n * math.pow(1.000000011, t)) ```
output
1
83,831
3
167,663
Provide tags and a correct Python 3 solution for this coding contest problem. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040
instruction
0
83,832
3
167,664
Tags: math Correct Solution: ``` n, t = map(int, input().split()) ans = 1.000000011 ** t * n print(ans) ```
output
1
83,832
3
167,665
Provide tags and a correct Python 3 solution for this coding contest problem. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040
instruction
0
83,833
3
167,666
Tags: math Correct Solution: ``` n,t = map(int,input().split()) print(n*pow(1.000000011,t)) ```
output
1
83,833
3
167,667
Provide tags and a correct Python 3 solution for this coding contest problem. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040
instruction
0
83,834
3
167,668
Tags: math Correct Solution: ``` n,t=input().split() n,t=int(n),int(t) print(n*pow(1.000000011,t)) ```
output
1
83,834
3
167,669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040 Submitted Solution: ``` n,t = map(int,input().split() ); print( n * (1.000000011 ** t)); ```
instruction
0
83,835
3
167,670
Yes
output
1
83,835
3
167,671
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040 Submitted Solution: ``` n,t=[int(i) for i in input().split()] print(n*pow(1.000000011,t)) ```
instruction
0
83,836
3
167,672
Yes
output
1
83,836
3
167,673
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040 Submitted Solution: ``` import sys import string from collections import Counter, defaultdict from math import fsum, sqrt, gcd, ceil, factorial from operator import * from itertools import accumulate inf = float("inf") # input = sys.stdin.readline flush = lambda: sys.stdout.flush comb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - y) en = lambda x: list(enumerate(x)) # inputs # ip = lambda : input().rstrip() ip = lambda: input() ii = lambda: int(input()) r = lambda: map(int, input().split()) rr = lambda: list(r()) a, b = r() x = 1.000000011 a = a * (x ** b) print(f"{a:.30f}") ```
instruction
0
83,837
3
167,674
Yes
output
1
83,837
3
167,675
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040 Submitted Solution: ``` a,b = map(int,input().split()) x = 1.000000011 print(a*x**b) ```
instruction
0
83,838
3
167,676
Yes
output
1
83,838
3
167,677
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040 Submitted Solution: ``` s = input() S = s.split() transistors = int(S[0]) seconds = int(S[1]) a1 = 1 a2 = 1 a3 = 1 for i in range(1000): a1 = a1*1.000000011 for i in range(1000): a2 = a2*a1 for i in range(1000): a3 = a3*a2 print(a1) print(a2) print(a3) local0 = seconds%1000 seconds = int((seconds-local0)/1000) local1 = seconds%1000 seconds = int((seconds-local1)/1000) local2 = seconds%1000 seconds = int((seconds-local2)/1000) local3 = seconds%1000 print(local0) print(local1) print(local2) print(local3) for i in range(local0): transistors = transistors*1.000000011 for i in range(local1): transistors = transistors*a1 for i in range(local2): transistors = transistors*a2 for i in range(local3): transistors = transistors*a3 print(transistors) ```
instruction
0
83,839
3
167,678
No
output
1
83,839
3
167,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040 Submitted Solution: ``` n, t = map(int, input().split()) print(1 + n * 3 * (n + 1)) ```
instruction
0
83,840
3
167,680
No
output
1
83,840
3
167,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040 Submitted Solution: ``` print(25) ```
instruction
0
83,841
3
167,682
No
output
1
83,841
3
167,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well. You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times. Input The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. Output Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6. Examples Input 1000 1000000 Output 1011.060722383550382782399454922040 Submitted Solution: ``` a, b = [int(i) for i in input().split()] for i in range(a, b): a *= 1.000000011 print(a) ```
instruction
0
83,842
3
167,684
No
output
1
83,842
3
167,685
Provide tags and a correct Python 3 solution for this coding contest problem. The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which is a circular area Ci described by a center (xi, yi) and a radius ri. No two ranges' borders have more than one common point, that is for every pair (i, j) (1 ≤ i < j ≤ n) either ranges Ci and Cj are disjoint, or one of them is a subset of the other. Note that it's possible that two ranges' borders share a single common point, but no two dancers have exactly the same ranges. Tsukihi, being one of them, defines the spaciousness to be the area covered by an odd number of movement ranges of dancers who are moving. An example is shown below, with shaded regions representing the spaciousness if everyone moves at the same time. <image> But no one keeps moving for the whole night after all, so the whole night's time is divided into two halves — before midnight and after midnight. Every dancer moves around in one half, while sitting down with friends in the other. The spaciousness of two halves are calculated separately and their sum should, of course, be as large as possible. The following figure shows an optimal solution to the example above. <image> By different plans of who dances in the first half and who does in the other, different sums of spaciousness over two halves are achieved. You are to find the largest achievable value of this sum. Input The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) with radius ri. Output Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 5 2 1 6 0 4 1 2 -1 3 1 -2 1 4 -1 1 Output 138.23007676 Input 8 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 Output 289.02652413 Note The first sample corresponds to the illustrations in the legend.
instruction
0
83,889
3
167,778
Tags: dfs and similar, dp, geometry, greedy, trees Correct Solution: ``` from sys import stdin, stdout import math def dist(x,y): return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5 # Is b inside a def inside(a,b): if dist(b,a)<a[2]: return True else: return False n = int(stdin.readline().rstrip()) pointList=[] for _ in range(n): x,y,r = map(int,stdin.readline().rstrip().split()) pointList.append((x,y,r)) pointList.sort(key = lambda x: x[2],reverse=True) positiveCounter = [0]*n group = [0]*n parent = [-1]*n spaciousness=0 for i in range(n): contained = -1 for j in range(i-1,-1,-1): if inside(pointList[j],pointList[i]): contained=j break if contained<0: positiveCounter[i]=1 group[i]=1 spaciousness+=math.pi*pointList[i][2]*pointList[i][2] else: parent[i]=j group[i] = 3-group[j] if parent[j]>=0: positiveCounter[i] = positiveCounter[j]*-1 spaciousness+=math.pi*pointList[i][2]*pointList[i][2]*positiveCounter[i] else: positiveCounter[i]=1 spaciousness+=math.pi*pointList[i][2]*pointList[i][2]*positiveCounter[i] print(spaciousness) ```
output
1
83,889
3
167,779
Provide tags and a correct Python 3 solution for this coding contest problem. The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which is a circular area Ci described by a center (xi, yi) and a radius ri. No two ranges' borders have more than one common point, that is for every pair (i, j) (1 ≤ i < j ≤ n) either ranges Ci and Cj are disjoint, or one of them is a subset of the other. Note that it's possible that two ranges' borders share a single common point, but no two dancers have exactly the same ranges. Tsukihi, being one of them, defines the spaciousness to be the area covered by an odd number of movement ranges of dancers who are moving. An example is shown below, with shaded regions representing the spaciousness if everyone moves at the same time. <image> But no one keeps moving for the whole night after all, so the whole night's time is divided into two halves — before midnight and after midnight. Every dancer moves around in one half, while sitting down with friends in the other. The spaciousness of two halves are calculated separately and their sum should, of course, be as large as possible. The following figure shows an optimal solution to the example above. <image> By different plans of who dances in the first half and who does in the other, different sums of spaciousness over two halves are achieved. You are to find the largest achievable value of this sum. Input The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) with radius ri. Output Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 5 2 1 6 0 4 1 2 -1 3 1 -2 1 4 -1 1 Output 138.23007676 Input 8 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 Output 289.02652413 Note The first sample corresponds to the illustrations in the legend.
instruction
0
83,890
3
167,780
Tags: dfs and similar, dp, geometry, greedy, trees Correct Solution: ``` import sys input = sys.stdin.readline from collections import * from math import pi def contain(i, j): xi, yi, ri = xyr[i] xj, yj, rj = xyr[j] if ri<rj: return False d2 = (xi-xj)**2+(yi-yj)**2 return d2<=(ri-rj)**2 def bfs(s): q = deque([s]) dist[s] = 0 while q: v = q.popleft() for nv in G[v]: if dist[nv]==-1: dist[nv] = dist[v]+1 q.append(nv) return dist n = int(input()) xyr = [tuple(map(int, input().split())) for _ in range(n)] ins = [0]*n outs = defaultdict(list) for i in range(n): for j in range(n): if i==j: continue if contain(i, j): ins[j] += 1 outs[i].append(j) q = deque([i for i in range(n) if ins[i]==0]) G = [[] for _ in range(n)] is_root = [True]*n while q: v = q.popleft() for nv in outs[v]: ins[nv] -= 1 if ins[nv]==0: G[v].append(nv) is_root[nv] = False q.append(nv) dist = [-1]*n for i in range(n): if is_root[i]: bfs(i) ans = 0 for i in range(n): r = xyr[i][2] if dist[i]==0 or dist[i]%2==1: ans += r**2 else: ans -= r**2 print(ans*pi) ```
output
1
83,890
3
167,781
Provide tags and a correct Python 3 solution for this coding contest problem. The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which is a circular area Ci described by a center (xi, yi) and a radius ri. No two ranges' borders have more than one common point, that is for every pair (i, j) (1 ≤ i < j ≤ n) either ranges Ci and Cj are disjoint, or one of them is a subset of the other. Note that it's possible that two ranges' borders share a single common point, but no two dancers have exactly the same ranges. Tsukihi, being one of them, defines the spaciousness to be the area covered by an odd number of movement ranges of dancers who are moving. An example is shown below, with shaded regions representing the spaciousness if everyone moves at the same time. <image> But no one keeps moving for the whole night after all, so the whole night's time is divided into two halves — before midnight and after midnight. Every dancer moves around in one half, while sitting down with friends in the other. The spaciousness of two halves are calculated separately and their sum should, of course, be as large as possible. The following figure shows an optimal solution to the example above. <image> By different plans of who dances in the first half and who does in the other, different sums of spaciousness over two halves are achieved. You are to find the largest achievable value of this sum. Input The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) with radius ri. Output Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 5 2 1 6 0 4 1 2 -1 3 1 -2 1 4 -1 1 Output 138.23007676 Input 8 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 Output 289.02652413 Note The first sample corresponds to the illustrations in the legend.
instruction
0
83,891
3
167,782
Tags: dfs and similar, dp, geometry, greedy, trees Correct Solution: ``` n = int(input()) d = [1] * n p = [[] for i in range(n)] def f(): x, y, r = map(int, input().split()) return r * r, x, y t = sorted(f() for i in range(n)) for i in range(n): r, x, y = t[i] for j in range(i + 1, n): s, a, b = t[j] if (a - x) ** 2 + (b - y) ** 2 < s: p[j].append(i) d[i] = 0 break def f(i): s = t[i][0] q = [(1, j) for j in p[i]] while q: d, i = q.pop() s += d * t[i][0] q += [(-d, j) for j in p[i]] return s print(3.1415926536 * sum(f(i) for i in range(n) if d[i])) ```
output
1
83,891
3
167,783
Provide tags and a correct Python 3 solution for this coding contest problem. The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which is a circular area Ci described by a center (xi, yi) and a radius ri. No two ranges' borders have more than one common point, that is for every pair (i, j) (1 ≤ i < j ≤ n) either ranges Ci and Cj are disjoint, or one of them is a subset of the other. Note that it's possible that two ranges' borders share a single common point, but no two dancers have exactly the same ranges. Tsukihi, being one of them, defines the spaciousness to be the area covered by an odd number of movement ranges of dancers who are moving. An example is shown below, with shaded regions representing the spaciousness if everyone moves at the same time. <image> But no one keeps moving for the whole night after all, so the whole night's time is divided into two halves — before midnight and after midnight. Every dancer moves around in one half, while sitting down with friends in the other. The spaciousness of two halves are calculated separately and their sum should, of course, be as large as possible. The following figure shows an optimal solution to the example above. <image> By different plans of who dances in the first half and who does in the other, different sums of spaciousness over two halves are achieved. You are to find the largest achievable value of this sum. Input The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) with radius ri. Output Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 5 2 1 6 0 4 1 2 -1 3 1 -2 1 4 -1 1 Output 138.23007676 Input 8 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 Output 289.02652413 Note The first sample corresponds to the illustrations in the legend.
instruction
0
83,892
3
167,784
Tags: dfs and similar, dp, geometry, greedy, trees Correct Solution: ``` import sys input = sys.stdin.buffer.readline from math import pi n = int(input()) circles = [list(map(int,input().split())) for i in range(n)] circles.sort(key = lambda x : -x[2]) mx = 0 groups = [] pars = [] for i in range(n): x,y,r = circles[i] added = -1 for j in range(len(groups)): xg,yg,rg = groups[j][0] mx_r = (r + ((x-xg)**2+(y-yg)**2)**0.5) if rg - mx_r > -1: # mx_r at least 2 greater than rg if not inside # thus use -1 to avoid precision issues added = j break if added == -1: groups.append([[x,y,r]]) pars.append([0]) else: pars[added].append(0) for j in range(len(groups[added])): xg, yg, rg = groups[added][j] mx_r = (r + ((x - xg) ** 2 + (y - yg) ** 2) ** 0.5) if rg - mx_r > -1: pars[added][-1] += 1 groups[added].append([x, y, r]) for i in range(len(groups)): top_circles = 0 for j in range(len(groups[i])): if pars[i][j] <= 1: mx += pi*groups[i][j][2]**2 else: mx += (-1+2*(pars[i][j]%2))*pi*groups[i][j][2]**2 print(mx) ```
output
1
83,892
3
167,785
Provide tags and a correct Python 3 solution for this coding contest problem. The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which is a circular area Ci described by a center (xi, yi) and a radius ri. No two ranges' borders have more than one common point, that is for every pair (i, j) (1 ≤ i < j ≤ n) either ranges Ci and Cj are disjoint, or one of them is a subset of the other. Note that it's possible that two ranges' borders share a single common point, but no two dancers have exactly the same ranges. Tsukihi, being one of them, defines the spaciousness to be the area covered by an odd number of movement ranges of dancers who are moving. An example is shown below, with shaded regions representing the spaciousness if everyone moves at the same time. <image> But no one keeps moving for the whole night after all, so the whole night's time is divided into two halves — before midnight and after midnight. Every dancer moves around in one half, while sitting down with friends in the other. The spaciousness of two halves are calculated separately and their sum should, of course, be as large as possible. The following figure shows an optimal solution to the example above. <image> By different plans of who dances in the first half and who does in the other, different sums of spaciousness over two halves are achieved. You are to find the largest achievable value of this sum. Input The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) with radius ri. Output Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 5 2 1 6 0 4 1 2 -1 3 1 -2 1 4 -1 1 Output 138.23007676 Input 8 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 Output 289.02652413 Note The first sample corresponds to the illustrations in the legend.
instruction
0
83,893
3
167,786
Tags: dfs and similar, dp, geometry, greedy, trees Correct Solution: ``` import sys def inside(a,b): return ((a[0]-b[0])**2 + (a[1]-b[1])**2) < (a[2]+b[2])**2 def main(): pi = 3.14159265358979323 n = int(sys.stdin.readline()) a = [] p = [-1]*n for i in range(n): x,y,r = map(int,sys.stdin.readline().split()) a.append([x,y,r]) for i in range(n): for j in range(n): if i==j : continue if inside(a[i],a[j]): if a[i][2] < a[j][2]: if p[i] == -1: p[i] = j elif a[p[i]][2]>a[j][2]: p[i] = j else: if p[j] == -1: p[j] = i elif a[p[j]][2]>a[i][2]: p[j] = i q = [] for i in range(n): if p[i] == -1: q.append((i,True)) s = len(q) ans = 0.0 for i in range(s): c, b = q[i] for j in range(n): if p[j] == c: q.append((j,True)) ans+= pi * a[c][2] * a[c][2] q = q[s:] while len(q)!=0 : c,b = q.pop() for j in range(n): if p[j] == c: q.append((j,not b)) if b: ans+= pi * a[c][2] * a[c][2] else: ans-= pi * a[c][2] * a[c][2] print(ans) main() ```
output
1
83,893
3
167,787
Provide tags and a correct Python 3 solution for this coding contest problem. The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which is a circular area Ci described by a center (xi, yi) and a radius ri. No two ranges' borders have more than one common point, that is for every pair (i, j) (1 ≤ i < j ≤ n) either ranges Ci and Cj are disjoint, or one of them is a subset of the other. Note that it's possible that two ranges' borders share a single common point, but no two dancers have exactly the same ranges. Tsukihi, being one of them, defines the spaciousness to be the area covered by an odd number of movement ranges of dancers who are moving. An example is shown below, with shaded regions representing the spaciousness if everyone moves at the same time. <image> But no one keeps moving for the whole night after all, so the whole night's time is divided into two halves — before midnight and after midnight. Every dancer moves around in one half, while sitting down with friends in the other. The spaciousness of two halves are calculated separately and their sum should, of course, be as large as possible. The following figure shows an optimal solution to the example above. <image> By different plans of who dances in the first half and who does in the other, different sums of spaciousness over two halves are achieved. You are to find the largest achievable value of this sum. Input The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) with radius ri. Output Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 5 2 1 6 0 4 1 2 -1 3 1 -2 1 4 -1 1 Output 138.23007676 Input 8 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 Output 289.02652413 Note The first sample corresponds to the illustrations in the legend.
instruction
0
83,894
3
167,788
Tags: dfs and similar, dp, geometry, greedy, trees Correct Solution: ``` s = 0 t = [list(map(int, input().split())) for i in range(int(input()))] f = lambda b: a[2] < b[2] and (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2 <= (a[2] - b[2]) ** 2 for a in t: k = sum(f(b) for b in t) s += (-1, 1)[(k < 1) + k & 1] * a[2] ** 2 print(3.1415926536 * s) ```
output
1
83,894
3
167,789
Provide tags and a correct Python 3 solution for this coding contest problem. The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which is a circular area Ci described by a center (xi, yi) and a radius ri. No two ranges' borders have more than one common point, that is for every pair (i, j) (1 ≤ i < j ≤ n) either ranges Ci and Cj are disjoint, or one of them is a subset of the other. Note that it's possible that two ranges' borders share a single common point, but no two dancers have exactly the same ranges. Tsukihi, being one of them, defines the spaciousness to be the area covered by an odd number of movement ranges of dancers who are moving. An example is shown below, with shaded regions representing the spaciousness if everyone moves at the same time. <image> But no one keeps moving for the whole night after all, so the whole night's time is divided into two halves — before midnight and after midnight. Every dancer moves around in one half, while sitting down with friends in the other. The spaciousness of two halves are calculated separately and their sum should, of course, be as large as possible. The following figure shows an optimal solution to the example above. <image> By different plans of who dances in the first half and who does in the other, different sums of spaciousness over two halves are achieved. You are to find the largest achievable value of this sum. Input The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) with radius ri. Output Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 5 2 1 6 0 4 1 2 -1 3 1 -2 1 4 -1 1 Output 138.23007676 Input 8 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 Output 289.02652413 Note The first sample corresponds to the illustrations in the legend.
instruction
0
83,895
3
167,790
Tags: dfs and similar, dp, geometry, greedy, trees Correct Solution: ``` from collections import namedtuple from math import hypot, pi def contains(fst, scd): return hypot(fst.x - scd.x, fst.y - scd.y) < fst.r def area(circle): return pi * circle.r ** 2 def find_prev(side, circle): for prev in reversed(side): if contains(prev, circle): return prev Circle = namedtuple('Circle', 'x y r') n = int(input()) cs = [] for i in range(n): cs.append(Circle(*map(int, input().split()))) cs = sorted(cs, key=lambda circle: -circle.r) ans = 0.0 counts = dict() left = [] right = [] for ind, cur in enumerate(cs): prev_left = find_prev(left, cur) prev_right = find_prev(right, cur) if prev_left is None: left.append(cur) counts[cur] = True ans += area(cur) elif prev_right is None: right.append(cur) counts[cur] = True ans += area(cur) elif counts[prev_left]: left.append(cur) counts[cur] = False ans -= area(cur) else: left.append(cur) counts[cur] = True ans += area(cur) print(ans) ```
output
1
83,895
3
167,791
Provide tags and a correct Python 3 solution for this coding contest problem. The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which is a circular area Ci described by a center (xi, yi) and a radius ri. No two ranges' borders have more than one common point, that is for every pair (i, j) (1 ≤ i < j ≤ n) either ranges Ci and Cj are disjoint, or one of them is a subset of the other. Note that it's possible that two ranges' borders share a single common point, but no two dancers have exactly the same ranges. Tsukihi, being one of them, defines the spaciousness to be the area covered by an odd number of movement ranges of dancers who are moving. An example is shown below, with shaded regions representing the spaciousness if everyone moves at the same time. <image> But no one keeps moving for the whole night after all, so the whole night's time is divided into two halves — before midnight and after midnight. Every dancer moves around in one half, while sitting down with friends in the other. The spaciousness of two halves are calculated separately and their sum should, of course, be as large as possible. The following figure shows an optimal solution to the example above. <image> By different plans of who dances in the first half and who does in the other, different sums of spaciousness over two halves are achieved. You are to find the largest achievable value of this sum. Input The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) with radius ri. Output Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 5 2 1 6 0 4 1 2 -1 3 1 -2 1 4 -1 1 Output 138.23007676 Input 8 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 Output 289.02652413 Note The first sample corresponds to the illustrations in the legend.
instruction
0
83,896
3
167,792
Tags: dfs and similar, dp, geometry, greedy, trees Correct Solution: ``` import math class circ: def __init__(self, x, y, r): self.x = x*1.0 self.y = y*1.0 self.r = r*1.0 n = 0 n = int(input()) vec = [] for i in range(n): st = input().split(' ') a = int(st[0]) b = int(st[1]) c = int(st[2]) vec.append(circ(a,b,c)) gr = [[] for i in range(n)] pad = [-1 for i in range(n)] vis = [False for i in range(n)] for i in range(n): for k in range(n): if i == k: continue dist = math.hypot(vec[i].x - vec[k].x, vec[i].y - vec[k].y) if (dist < vec[k].r and vec[k].r > vec[i].r and (pad[i] < 0 or vec[k].r < vec[pad[i]].r)): pad[i] = k for i in range(n): if pad[i] < 0: continue gr[pad[i]].append(i) st = [] ans = 0.0 for i in range(n): if pad[i] >= 0 or vis[i]: continue st.append((i, 0)) while len(st) > 0: node, level = st.pop() vis[node] = True mult = -1.0 if level == 0 or level%2 == 1: mult = 1.0 ans += (mult * (vec[node].r * vec[node].r * math.pi)) for next in gr[node]: st.append((next, level+1)) print(ans) ```
output
1
83,896
3
167,793