Everything is bad
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Burdochvirus is raging in the city of Morshyn, infecting block after block.
To make things harder, let’s imagine that the city is a square grid, where each cell represents a single block. A cell with 1 represents a block that has the virus, while 0 represents a healthy one. It is known that when the virus in a certain cell activates, it chooses a row or a column of the grid, after which the residents of all blocks in that row or column will be at risk of illness.
Your task is to determine whether there is a risk that the residents of all blocks will be at risk of illness. In other words, can the viruses in each infected block choose a direction (row or column) such that all blocks are at risk?
Input
The first line gives two integers \(n\) and \(m\) — the number of rows and columns in the grid representing the city.
The next \(n\) lines each contain \(m\) digits, 0 or 1, representing the infection status of each block in the city.
Output
In a single line, output YES if there is a risk for all
blocks, or NO otherwise.
Constraints
\(1 \le n, m \le 100\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 2 3 010 100 | YES |
| Input (stdin) | Output (stdout) |
|---|---|
| 3 4 1011 0000 1001 | NO |
Notes
In the first test, the virus in the first row can threaten all blocks of the first row, and the virus in the second row can threaten all blocks of the second. In this case, all cells of the grid will be at risk.
In the second test, the cell at the intersection of the second row and the second column will never be at risk.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|