#K34467. Transform the Grid to Ones

    ID: 25316 Type: Default 1000ms 256MiB

Transform the Grid to Ones

Transform the Grid to Ones

You are given a grid with R rows and C columns, where each cell contains either '0' or '1'. Your task is to determine whether it is possible to transform the entire grid to '1's by performing a series of operations. In one operation, you are allowed to flip a subgrid (i.e. change all its cells to '1's) only if its top-left cell is '1'.

The constraint can be formally expressed as: for every cell \(a_{i,j}\) that is '0', there must exist at least one cell \(a_{x,y}\) with \(0 \le x \le i\) and \(0 \le y \le j\) such that \(a_{x,y} = 1\). If this condition is met for every cell, then the entire grid can be transformed to ones.

inputFormat

The first line contains two integers R and C representing the number of rows and columns of the grid, respectively.

Each of the following R lines contains C space-separated characters ('0' or '1') representing the grid.

outputFormat

Output a single line containing either Yes if it is possible to transform the grid entirely to 1s, or No otherwise.

## sample
3 3
1 1 1
1 0 1
1 1 1
Yes

</p>