It is the final leg of the most famous amazing race. The top 'n' competitors have made…
- User
It is the final leg of the most famous amazing race. The top 'n' competitors have made it to the final. The final race has just begun. The race has 'm' checkpoints. Each team can reach any of the 'm' checkpoint but after a team reaches a particular checkpoint that checkpoint gets closed and is not open to any other team. The race ends when 'k' teams finish the race. Each team travel at a constant speed throughout the race which might be different for different teams. Given the coordinates of n teams and m checkpoints and speed of individual team return the value of minimum time needed to end the race.
NOTE:
The time required for a team at coordinate (p,q) with speed 's' to reach a checkpoint at coordinate (x,y) is given by:
t = ceil( ((p-x)^2 + (q-y)^2) / s^2 ). For example if distance is 5 units and speed is 2 units then required time = ceil(25/4) = 7. Input Format:
The first line contains 3 integers n, m and k denoting the total number of competitors, total number of checkpoints and the minimum number of teams that must complete the race in order to end the race.
This is followed by n lines each indicating the coordinates of n teams.
This is followed by m lines each indicating the coordinates of m checkpoints.
This is followed by n integers each denoting the speed of the ith team
Output Format:
Print the minimum time required to end the race.
Constraints:
1 ≤ n ≤ 200
1 ≤ m ≤ 200
1 ≤ k ≤ n
0 ≤ x coordinate of team and checkpoint ≤10^6
0 ≤ y coordinate of team and checkpoint ≤10^6
1 ≤ speed of team ≤ 50
SAMPLE INPUT 2 3 1 0 1 0 0 0 10 27 29 458 9651 5 3
SAMPLE OUTPUT 4
Explanation
For the race to finish in the minimum time the team at location (0,1) can reach the checkpoint at (0,10) .The distance between them is 9 and speed of team is 5 so required time is ceil(99))/(55))=ceil(81/25)=4.
Assistant
from collections import deque def max_bipartite_matching(graph, num_left, num_right): pair_u = [-1] * num_left pair_v = [-1] * num_right dist = [0] * num_left result = 0 while bfs(graph, pair_u, pair_v, dist): for u in range(num_left): if pair_u[u] == -1: if dfs(u, graph, pair_u, pair_v, dist): result += 1 return result def bfs(graph, pair_u, pair_v, dist): queue = deque() n = len(graph) for u in range(n): if pair_u[u] == -1: dist[u] = 0 queue.append(u) else: dist[u] = float('inf') dist_null = float('inf') while queue: u = queue.popleft() if dist[u] < dist_null: for v in graph[u]: if pair_v[v] == -1: dist_null = dist[u] + 1 elif dist[pair_v[v]] == float('inf'): dist[pair_v[v]] = dist[u] + 1 queue.append(pair_v[v]) return dist_null != float('inf') def dfs(u, graph, pair_u, pair_v, dist): for v in graph[u]: if pair_v[v] == -1 or (dist[pair_v[v]] == dist[u] + 1 and dfs(pair_v[v], graph, pair_u, pair_v, dist)): pair_u[u] = v pair_v[v] = u return True dist[u] = float('inf') return False n, m, k = map(int, input().split()) teams = [tuple(map(int, input().split())) for _ in range(n)] checkpoints = [tuple(map(int, input().split())) for _ in range(m)] speeds = list(map(int, input().split())) times = [] for i in range(n): x1, y1 = teams[i] s = speeds[i] s_sq = s * s row = [] for j in range(m): x2, y2 = checkpoints[j] dx = x1 - x2 dy = y1 - y2 dist_sq = dx * dx + dy * dy time = (dist_sq + s_sq - 1) // s_sq row.append(time) times.append(row) low = 0 high = max(t for row in times for t in row) while low < high: mid = (low + high) // 2 graph = [[] for _ in range(n)] for i in range(n): for j in range(m): if times[i][j] <= mid: graph[i].append(j) current_matching = max_bipartite_matching(graph, n, m) if current_matching >= k: high = mid else: low = mid + 1 print(low)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.