#C2071. Shortest Path in a Grid

    ID: 45347 Type: Default 1000ms 256MiB

Shortest Path in a Grid

Shortest Path in a Grid

You are given a grid representing a matrix of dimensions \(m \times n\) where each cell is either '-' (an open cell) or '+' (an obstacle). Your task is to compute the length of the shortest path from the top-left corner (cell \( (0,0)\)) to the bottom-right corner (cell \( (m-1,n-1)\)). You can move in the four cardinal directions: up, down, left, and right. You cannot move into a cell containing an obstacle. If no such path exists, output \(-1\).

Note: The path length is defined as the number of moves required to reach the destination. For example, if the start and end cells are adjacent, the answer is 1.

Example:

Input:
3
---
-+-
---

Output: 4

</p>

inputFormat

The first line contains an integer \(m\), the number of rows in the grid. Each of the next \(m\) lines contains a string representing a row of the grid. All rows have the same length \(n\).

outputFormat

Output a single integer: the length of the shortest path from the top-left cell to the bottom-right cell, or \(-1\) if no such path exists.

## sample
3
---
-+-
---
4