#C3535. Count Paths With Obstacles
Count Paths With Obstacles
Count Paths With Obstacles
You are given a grid with dimensions (n) and (m). Each cell in the grid is either free (denoted by 0) or contains an obstacle (denoted by 1). Your task is to determine the number of distinct paths from the top-left corner to the bottom-right corner of the grid, where you can only move either down or right. The answer must be computed modulo (998244353). Note that if either the starting cell or the destination cell is an obstacle, then there is no valid path.
inputFormat
The first line contains two integers (n) and (m), representing the number of rows and columns respectively. This is followed by (n) lines, each containing (m) space-separated integers (0 or 1) representing the grid's cells.
outputFormat
Output a single integer representing the number of distinct paths from the top-left to the bottom-right cell in the grid, computed modulo (998244353).## sample
3 3
0 0 0
0 1 0
0 0 0
2