CF1647B.Madoka and the Elegant Gift

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

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.

魔理沙的父亲刚刚在 Mathub 网站上达到了 100 万订阅者!因此,该网站决定向他颁发一枚专属奖章——Mathhub 的“比特按钮”(Bit Button)!

“比特按钮”是一个具有 nn 行 mm 列的矩形表格,每个格子中填有 00 或 11。魔理沙在研究该表格时发现:

  • 子矩形 AA 包含于子矩形 BB,当且仅当不存在属于 AA 却不属于 BB 的格子;
  • 两个子矩形相交,当且仅当存在一个格子同时属于这两个子矩形;
  • 一个子矩形被称为黑色的,当且仅当其内部不包含值为 00 的格子;
  • 一个子矩形被称为优美的,当且仅当它是黑色的,且不被任何其他黑色子矩形所包含;
  • 整个表格被称为优雅的,当且仅当其中不存在两个相交的优美子矩形。

例如,在第一张示意图中,红色子矩形是优美的;但在第二张图中它却不是优美的,因为它被紫色子矩形所包含。

请帮助魔理沙判断该表格是否为优雅的。

输入格式

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

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤2001 \le t \le 200),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个正整数 n,mn, m(1≤n,m≤1001 \le n, m \le 100)。

接下来的 nn 行,每行包含一个长度为 mm 的字符串,仅由字符 0 和 1 组成——表示表格的描述。

保证所有测试用例中 nn 的总和与 mm 的总和均不超过 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).

对于每个测试用例,如果其表格是优美的,则输出 “YES”,否则输出 “NO”。

你可以以任意大小写形式输出每个字母(例如,“YES”、“Yes”、“yes”、“yEs” 均会被识别为肯定回答)。

输入输出样例

  • 输入#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.

在第二个测试用例中,该表格不优雅,因为红色和紫色子矩形都是优美的且相交。

在第四个测试用例中,该表格不优雅,因为红色和紫色子矩形都是优美的且相交。

输入解题思路,AI测评打分。不知道怎么写?

首页