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
import sys from collections import deque def hopcroft_karp(graph, U, V): pair_U = [None] * U pair_V = [None] * V dist = [0] * U def bfs(): queue = deque() for u in range(U): if pair_U[u] is None: 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] is None: 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): for v in graph[u]: if pair_V[v] is None or (dist[pair_V[v]] == dist[u] + 1 and dfs(pair_V[v])): pair_U[u] = v pair_V[v] = u return True dist[u] = float('inf') return False result = 0 while bfs(): for u in range(U): if pair_U[u] is None: if dfs(u): result += 1 return result def main(): n, m, k = map(int, sys.stdin.readline().split()) teams = [tuple(map(int, sys.stdin.readline().split())) for _ in range(n)] checkpoints = [tuple(map(int, sys.stdin.readline().split())) for _ in range(m)] speeds = list(map(int, sys.stdin.readline().split())) # Precompute all possible times t = [] max_time = 0 for i in range(n): tx, ty = teams[i] s = speeds[i] s_sq = s * s row = [] for j in range(m): cx, cy = checkpoints[j] dx = tx - cx dy = ty - cy dist_sq = dx * dx + dy * dy time = (dist_sq + s_sq - 1) // s_sq row.append(time) if time > max_time: max_time = time t.append(row) low = 0 high = max_time answer = high while low <= high: mid = (low + high) // 2 # Build the graph for this mid graph = [[] for _ in range(n)] for i in range(n): for j in range(m): if t[i][j] <= mid: graph[i].append(j) # Compute maximum matching matching_size = hopcroft_karp(graph, n, m) if matching_size >= k: answer = mid high = mid - 1 else: low = mid + 1 print(answer) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.