QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#3750. All-1 Submatrix

统计

Bobo has written an $n \times m$ matrix $A_{i, j}$.

  • Initially, he sets all elements $A_{i, j}$ ($1 \leq i \leq n, 1 \leq j \leq m$) to 0.
  • Then, he chooses $4$ integers $x_1, x_2, y_1, y_2$ such that $1 \leq x_1 \leq x_2 \leq n$ and $1 \leq y_1 \leq y_2 \leq m$, and sets all elements $A_{i, j}$ satisfying $x_1 \leq i \leq x_2$ and $y_1 \leq j \leq y_2$ to 1.

Given an $n \times m$ matrix $A_{i, j}$, determine whether it is a matrix that could have been written by Bobo.

Input

The input contains multiple test cases. Process until the end of the file.

Each test case starts with two integers $n$ and $m$.

The next $n$ lines each contain $m$ integers $A_{i, 1}, A_{i, 2}, \dots, A_{i, m}$.

  • $1 \leq n, m \leq 10$
  • $A_{i, j} \in \{0, 1\}$
  • At most $1000$ test cases.

Output

For each test case, output Yes if the given matrix could have been written by Bobo, otherwise output No.

Examples

Input 1

2 2
11
10
3 3
000
001
000
3 4
1111
1111
1111

Output 1

No
Yes
Yes

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.