All problems

Problem 486

Set Matrix Zeroes

Medium · 20 pts · Matrix, Hash Table

Problem

For every cell of an R x C matrix that contains 0, set its entire row and its entire column to 0. Only the zeros of the original matrix count: zeros that you create while updating must not spread further. Print the resulting matrix. Record which rows and columns contain a zero first, and only then update the matrix.

Input

First line: R and C. Next R lines: C integers each.

Output

Print the resulting matrix: R lines of C integers.

Constraints

1 <= R, C <= 200; -1000000000 <= value <= 1000000000

Example input

3 3
1 1 1
1 0 1
1 1 1

Example output

1 0 1
0 0 0
1 0 1

Explanation

In 1 1 1 / 1 0 1 / 1 1 1, the 0 is in the middle row and middle column, so both are cleared: 1 0 1 / 0 0 0 / 1 0 1.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: XOR of Subarray Queries Next: Game of Life