#K82732. Unique Paths in Grid with Obstacles

    ID: 36041 Type: Default 1000ms 256MiB

Unique Paths in Grid with Obstacles

Unique Paths in Grid with Obstacles

You are given a 2D grid of size \(m \times n\) where each cell is either empty (denoted by 0) or blocked (denoted by 1). Your task is to compute the number of unique paths from the top-left corner (cell \( (1,1) \)) to the bottom-right corner (cell \( (m,n) \)). You can only move either down or right at any point in time. Note that the starting and ending cells are guaranteed to be empty.

Input Format: The first line contains two integers \(m\) and \(n\), representing the number of rows and columns respectively. This is followed by \(m\) lines, each containing \(n\) integers (0 or 1) representing the grid.

Output Format: Output a single integer which is the number of unique paths from the top-left to the bottom-right corner.

Example:

Input:
3 3
0 0 0
0 1 0
0 0 0

Output: 2

</p>

inputFormat

The input is given via standard input (stdin) and follows the format below:

<m> <n>
<row1_element1> <row1_element2> ... <row1_elementn>
...
<rowm_element1> <rowm_element2> ... <rowm_elementn>

Where \(m\) is the number of rows, \(n\) is the number of columns and each following line represents a row of the grid, consisting of \(n\) space-separated integers (0 for an empty cell and 1 for a blocked cell).

outputFormat

The output should be a single integer printed to standard output (stdout) representing the number of unique paths from the top-left corner to the bottom-right corner of the grid.

## sample
3 3
0 0 0
0 1 0
0 0 0
2