Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost of a Path With Special Roads

Try to solve the Minimum Cost of a Path With Special Roads problem.

Statement

You are given an array start = [startX, startY] representing your initial position and an array target = [targetX, targetY] representing your destination on a 22D plane.

You can travel between any two points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) with a cost equal to the Manhattan distance ∣x2−x1∣+∣y2−y1∣|x_2 - x_1| + |y_2 - y_1|.

Additionally, you are provided with a 22D array specialRoads where specialRoads[i] = [x1_i, y1_i, x2_i, y2_i, cost_i] represents a directed special road that allows you to travel from (x1i,y1i)(x1_i, y1_i) to (x2i,y2i)(x2_i, y2_i) for a cost of cost_i. Each special road can be used any number of times.

Return the minimum cost required to travel from start to target.

Constraints:

  • start.length =target.length=2= {target.length} = 2

  • 1≤1 \leq startX ≤\leq targetX ≤105\leq 10^5

  • 1≤1 \leq startY ≤\leq targetY ≤105\leq 10^5

  • 1≤1 \leq specialRoads.length ≤200\leq 200

  • specialRoads[i].length =5= 5

  • startX ≤x1i,x2i≤\leq x1_i, x2_i \leq targetX

  • startY ≤y1i,y2i≤\leq y1_i, y2_i \leq targetY

  • 1≤costi≤1051 \leq cost_i \leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost of a Path With Special Roads

Try to solve the Minimum Cost of a Path With Special Roads problem.

Statement

You are given an array start = [startX, startY] representing your initial position and an array target = [targetX, targetY] representing your destination on a 22D plane.

You can travel between any two points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) with a cost equal to the Manhattan distance ∣x2−x1∣+∣y2−y1∣|x_2 - x_1| + |y_2 - y_1|.

Additionally, you are provided with a 22D array specialRoads where specialRoads[i] = [x1_i, y1_i, x2_i, y2_i, cost_i] represents a directed special road that allows you to travel from (x1i,y1i)(x1_i, y1_i) to (x2i,y2i)(x2_i, y2_i) for a cost of cost_i. Each special road can be used any number of times.

Return the minimum cost required to travel from start to target.

Constraints:

  • start.length =target.length=2= {target.length} = 2

  • 1≤1 \leq startX ≤\leq targetX ≤105\leq 10^5

  • 1≤1 \leq startY ≤\leq targetY ≤105\leq 10^5

  • 1≤1 \leq specialRoads.length ≤200\leq 200

  • specialRoads[i].length =5= 5

  • startX ≤x1i,x2i≤\leq x1_i, x2_i \leq targetX

  • startY ≤y1i,y2i≤\leq y1_i, y2_i \leq targetY

  • 1≤costi≤1051 \leq cost_i \leq 10^5