Inverted cells
Practice
3.5 (41 votes)
Algorithms
Depth first search
Graphs
Problem
79% Success 6367 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given a matrix \(n*m \). The matrix rows are numbered from \(1 \) to \(n\) from top to bottom and the matrix columns are numbered from \(1\) to \(m\) from left to right. The cells of the field at the intersection of the \(x^{th}\) row and the \(y^{th}\)column has coordinates \((x, y)\).

Every cell is empty or blocked. For every cell \((x, y)\), determine if you change the state of cell \((x, y)\)(empty to blocked or blocked to empty), then is it possible to reach cell \((n, m) \) from \((1, 1) \) by going only down and right.

Input format

  • The first line contains two space-separated numbers \(n, m \)  denoting the number of rows and columns.
  • Next \(n\) lines contain symbols. If the symbol on \((x, y)\) is '#', then the cell is blocked. Otherwise, if the symbol is '.', then the cell is empty.

Output format

Print \(n\)  lines where every line contains \(m\) numbers. Print 0 if it is impossible to reach \((n, m) \). Otherwise, print 1.

Constraints

\(1 \le n, m \le 10^3 \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
4 votes
Tags:
Bit ManipulationDepth First SearchEasyGraphs
Points:30
30 votes
Tags:
Depth First SearchEasyGraphs
Points:30
7 votes
Tags:
AlgorithmsBinary SearchDepth First SearchEasySearching