#C332. Delivery Route Optimization
Delivery Route Optimization
Delivery Route Optimization
You are given a grid representing travel costs, where each cell contains a non‐negative integer cost. You are also given a starting point and a destination point within the grid. Your task is to compute the shortest route from the start to the destination by moving in four directions (up, down, left, right). The cost of a route is defined as the sum of the costs of all cells visited excluding the starting cell, i.e.,
[ \text{Total Cost} = \sum_{i=1}^{k} cost(p_i)]
where (p_i) is the i-th cell in the path (after the start). Print the route as a space‐separated sequence of coordinates in the format (x,y)
from start to destination, followed by the total cost on the next line.
Assume the grid is a rectangle and all indices are zero-based.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains two integers (n) and (m), representing the number of rows and columns of the grid.
- The next (n) lines each contain (m) integers separated by spaces, describing the grid where each integer is the travel cost for that cell.
- The following line contains two integers representing the starting point coordinates (sx) and (sy).
- The last line contains two integers representing the destination point coordinates (dx) and (dy).
outputFormat
The output is printed to standard output (stdout) and consists of two lines:
- The first line shows the shortest route as a sequence of coordinates in the format
(x,y)
separated by spaces. - The second line shows the total travel cost (an integer) of that route (excluding the starting cell's cost).## sample
3 3
1 2 3
4 8 2
1 5 3
0 0
2 2
(0,0) (0,1) (0,2) (1,2) (2,2)
10
</p>