CF1647B.Madoka and the Elegant Gift

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Madoka's father just reached 11 million subscribers on Mathub! So the website decided to send him a personalized award — The Mathhub's Bit Button!

The Bit Button is a rectangular table with nn rows and mm columns with 00 or 11 in each cell. After exploring the table Madoka found out that:

  • A subrectangle AA is contained in a subrectangle BB if there's no cell contained in AA but not contained in BB .
  • Two subrectangles intersect if there is a cell contained in both of them.
  • A subrectangle is called black if there's no cell with value 00 inside it.
  • A subrectangle is called nice if it's black and it's not contained in another black subrectangle.
  • The table is called elegant if there are no two nice intersecting subrectangles.

For example, in the first illustration the red subrectangle is nice, but in the second one it's not, because it's contained in the purple subrectangle.

Help Madoka to determine whether the table is elegant.

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t2001 \le t \le 200 ) — the number of test cases. Description of the test cases follows.

The first line of each test case contains two positive integers n,mn, m ( 1n,m1001 \le n, m \le 100 ).

The next nn lines contain strings of length mm consisting of zeros and ones — the description of the table.

It is guaranteed that the sum of the values of nn and the sum of the values of mm for all test cases do not exceed 777777 .

输出格式

For each test case print "YES" if its table is elegant or print "NO" otherwise.

You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

输入输出样例

  • 输入#1

    5
    3 3
    100
    011
    011
    3 3
    110
    111
    110
    1 5
    01111
    4 5
    11111
    01010
    01000
    01000
    3 2
    11
    00
    11

    输出#1

    YES
    NO
    YES
    NO
    YES

说明/提示

In the second test case the table is not elegant, because the red and the purple subrectangles are nice and intersect.

In the fourth test case the table is not elegant, because the red and the purple subrectangles are nice and intersect.

首页