#C6737. Game of Life: One Iteration Simulation

    ID: 50530 Type: Default 1000ms 256MiB

Game of Life: One Iteration Simulation

Game of Life: One Iteration Simulation

This problem simulates one iteration of Conway's Game of Life. Given an initial grid configuration, update the grid based on the following rules (presented here in LaTeX format):

  • A live cell with fewer than $2$ live neighbors dies.
  • A live cell with $2$ or $3$ live neighbors lives on to the next generation.
  • A live cell with more than $3$ live neighbors dies.
  • A dead cell with exactly $3$ live neighbors becomes a live cell.

The grid is represented by a matrix of $0$s and $1$s, where $1$ indicates a live cell, and $0$ indicates a dead cell.

inputFormat

The first line of input contains two integers m and n, representing the number of rows and columns of the grid. Each of the following m lines contains n integers (each either 0 or 1) separated by spaces, representing the current state of the grid.

outputFormat

Output the grid after one iteration. The output should consist of m lines, each containing n integers separated by a single space. Each line corresponds to a row in the resulting grid.## sample

4 3
0 1 0
0 0 1
1 1 1
0 0 0
0 0 0

1 0 1 0 1 1 0 1 0

</p>