#C3968. Unique Paths in a Maze

    ID: 47453 Type: Default 1000ms 256MiB

Unique Paths in a Maze

Unique Paths in a Maze

In this problem, you are given a grid (maze) of size (N \times M). Each cell of the maze is either open (denoted by 0) or blocked (denoted by 1). You start at the top-left corner ((1,1)) and your goal is to reach the bottom-right corner ((N, M)). You can only move to the right or down from any cell. Your task is to count the number of unique paths from the start to the destination while avoiding blocked cells. If either the starting cell or the destination cell is blocked, the answer is 0.

Formally, if you are at cell ((i,j)), you can move to cell ((i, j+1)) or ((i+1, j)) provided that the cell is within the bounds of the maze and is not blocked.

inputFormat

The input is read from standard input (stdin). The first line contains two integers (N) and (M) separated by a space, representing the number of rows and columns of the maze. This is followed by (N) lines, each containing (M) integers (either 0 or 1) separated by spaces, representing the maze grid.

outputFormat

Output a single integer to standard output (stdout) representing the number of unique paths from the start cell ((1,1)) to the destination cell ((N, M)).## sample

2 2
0 0
0 0
2