Codeforces Round #777 B. Madoka nd the Elegant Gift

B. Madoka nd the Elegant Gift

time limit per test

1 second

memory limit per test

256 megabytes

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.

img

Help Madoka to determine whether the table is elegant.

Input

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤2001≤t≤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 (1≤n,m≤1001≤n,m≤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.

Output

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).

Example

input

Copy

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

output

Copy

YES
NO
YES
NO
YES

Note

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

img

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

img

题意,1构成的子矩阵不能相交,应该指的是构成的最大的子矩阵

看了看提示才想出来的,读题时间有点久了,不过原理太简单了,每个2x2矩阵中如果有3个1就不可以,如果有1个两个四个都可以,就没了…

#include<iostream>
#include<cstring>
using namespace std;
int a[800][800];
int main()
{
    int n;
    cin>>n;
    int x,y;
    while(n--){
        cin>>x>>y;
        char c;
        for(int i=1;i<=x;i++){
            for(int j=1;j<=y;j++){
            cin>>c;
            a[i][j]=c-'0';
            }
        }
        int flag=1;
        for(int i=1;i<x;i++){
            for(int j=1;j<y;j++){
                if(a[i][j] + a[i+1][j] + a[i][j+1] + a[i+1][j+1] == 3)flag=0;
            }
        }
        if(flag)cout<<"Yes"<<endl;
        else cout<<"NO"<<endl;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值