CF985B.Switches and Lamps

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where a__i, j = 1 if the i-th switch turns on the j-th lamp and a__i, j = 0 if the i-th switch is not connected to the j-th lamp.

Initially all m lamps are turned off.

Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards.

It is guaranteed that if you push all n switches then all m lamps will be turned on.

Your think that you have too many switches and you would like to ignore one of them.

Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on.

你有 nn 个开关和 mm 盏灯。第 ii 个开关会打开某一部分灯。该信息由一个 nn 行 mm 列的矩阵 aa 给出,其中若第 ii 个开关能打开第 jj 盏灯,则 ai,j=1a_{i,j} = 1;若第 ii 个开关与第 jj 盏灯未连接,则 ai,j=0a_{i,j} = 0。

初始时,全部 mm 盏灯均处于关闭状态。

开关的状态只能从“关”变为“开”。这意味着:若你按下两个或更多个连接到同一盏灯的开关,则只要其中任意一个开关被按下,该灯即被打开;此后,即使再按下任何与该灯相连的开关,该灯的状态也保持不变(即仍为“开”)。

题目保证:若你按下全部 nn 个开关,则所有 mm 盏灯都会被打开。

你认为开关数量过多,希望忽略其中一个开关。

你的任务是判断:是否存在某个开关,使得在忽略(即不使用)它的情况下,按下其余全部 n−1n-1 个开关,仍能使所有 mm 盏灯都被打开。

输入格式

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps.

The following n lines contain m characters each. The character a__i, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise.

It is guaranteed that if you press all n switches all m lamps will be turned on.

输入的第一行包含两个整数 nn 和 mm(1 ≤ n, m ≤ 20001 \leq n, m \leq 2000)——分别表示开关的数量和灯的数量。

接下来的 nn 行,每行包含 mm 个字符。字符 ai,ja_{i,j} 为 '1' 表示第 ii 个开关能够打开第 jj 盏灯,为 '0' 则表示不能。

保证:若将全部 nn 个开关都按下,则所有 mm 盏灯都将被打开。

输出格式

Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch.

如果存在一个开关,当你忽略它并按下其余的 n−1n-1 个开关时,所有 mm 盏灯都会被打开,则输出 "YES";否则(即不存在这样的开关),输出 "NO"。

输入输出样例

  • 输入#1

    4 5
    10101
    01000
    00111
    10000

    输出#1

    YES
  • 输入#2

    4 5
    10100
    01000
    00110
    00101

    输出#2

    NO

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

首页