Path on a board

Consider an n × n board, where n is odd. From each cell, we can move to
any of its (at most) four horizontally or vertically adjacent cells. For
each cell, we have to pay a certain positive cost when we go through it.
Compute the minimum cost of going from the center of the board to any
cell on its periphery.

Input

Input consists of several cases, each with n, followed by an n × n
matrix. You can assume that n is an odd number between 1 and 499, and
that all costs are integer numbers between 1 and 1000.

Output

For every case, print the minimum cost to go from the middle of the
board to any cell on the edge of the board.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T13:40:38.837Z

© Jutge.org, 2006–2026.
https://jutge.org
