Mighty ROOK

0

0 votes
Medium
Problem

Our topper nerd, Vinay is learning how to play Chess. Being a noobie, he is fascinated by the moves and attacks of a Rook (aka Tower). The rook moves horizontally or vertically, through any number of unoccupied squares. This is a Rook -
Rook


To make things a little more interesting, Vinay took the liberty of placing as many rooks as he want. As he is still learning chess, you have to tell him the rows and the columns that the rook\rooks can cover. Given a m x n matrix (chess board), if an rook is present in any cell, set its entire row and column to 0.


Input:
The first two lines contains integers m and n, which are the number of rows and columns which will be provided as input. This is followed by m lines, having n consecutive Integers less than 10, with a space between each pair of integers. The Rook is represented by 0. And, all the other pieces are represented by integers, other than 0.

Output:
The output will be m lines, having n consecutive Integers less than 10, with a space between each pair of integers. With 0 in whole row and column of the cell in which the rook is present.

Sample Input
2
2
1 2
0 3
Sample Output
0 2
0 0
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

In the given sample problem, a 2 x 2 chess board is given alongwith the positions of the pieces on the board in the line 3 & 4. As, there is only one rook present at (1,0) row 1 and column 0 are all made 0. And, the elements that do not belong in these rows and columns are printed in the output as it is.

Editor Image

?