Switches and Lamps
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 aconsisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, 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.

Input

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 ai, 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.

Output

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.

Examples
input

Copy
4 5
10101
01000
00111
10000
output

Copy
YES
input

Copy
4 5
10100
01000
00110
00101
output

Copy
NO
#include <iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<deque>
#include<vector>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007;
using namespace std;
int a[][];
int s[];
int main()
{
int n,m;
cin>>n>>m;
char b[];
memset(a,,sizeof(a));
for(int i=;i<=n;i++)
{
cin>>b;
for(int j=;j<=m;j++)
{
a[i][j]=b[j-]-'';
s[j]+=a[i][j];
}
}
bool f=;
int j;
for(int i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
if(s[j]-a[i][j]==) break;
}
if(j==m+) f=; }
if(f) cout<<"YES";
else cout<<"NO";
return ;
}

codeforce 985B Switches and Lamps(暴力+思维)的更多相关文章

  1. Switches and Lamps(思维)

    You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This inform ...

  2. codeforces 985B Switches and Lamps

    题意: 有n个开关,m盏灯. 一个开关可以控制多个灯,一旦一个灯开了之后,之后再对这个灯的操作就没用了. 问是否存在一个开关,去掉了这个开关之后,按下其它开关之后所有的灯还是亮的. 思路: 首先统计每 ...

  3. CF985B Switches and Lamps 思维 第十九

    Switches and Lamps time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  4. 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)

    湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...

  5. B. Switches and Lamps

    链接 [https://codeforces.com/contest/985/problem/B] 题意 给你n,m,分别是n个开关,m个灯 给一个n*m的字符矩阵aij=1,表示i可以控制j这个灯 ...

  6. 暴力/思维 HDOJ 5386 Cover

    题目传送门 /* 题意:给出刷墙的所有的方法,求一种顺序,使得原矩阵刷成目标矩阵 暴力:(题解)我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可 */ /* ...

  7. 【洛谷】P1275 魔板(暴力&思维)

    题目描述 有这样一种魔板:它是一个长方形的面板,被划分成n行m列的n*m个方格.每个方格内有一个小灯泡,灯泡的状态有两种(亮或暗).我们可以通过若干操作使魔板从一个状态改变为另一个状态.操作的方式有两 ...

  8. Codeforce Gym 100015I Identity Checker 暴力

    Identity Checker 题目连接: http://codeforces.com/gym/100015/attachments Description You likely have seen ...

  9. CF985B Switches and Lamps【矩阵操作/枚举】

    [链接]CF985B [题意]:给n盏灯,m个开关,每次按开关只能将灯从灯灭的状态转变为灯亮,问是否存在不按所有开关就将所有灯打开的方法. [分析]:有两种办法,一种代码复杂点,容易想到枚举去掉每一行 ...

随机推荐

  1. Centos6.5 安装gitlab 并使用自带的nginx

    Centos6.5 安装gitlab 并使用自带的nginx 1.安装依赖 yum -y install policycoreutils openssh-server openssh-clients ...

  2. 报错cannot be cast to javassist.util.proxy.Proxy

    出现这种错误还有一个原因:hibernate和struts中都有javassit的jar包,把其中的低版本删除就行了.

  3. stringToDateUtils 字符串转化日期

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; impor ...

  4. LCS 的 NlogN作法

    这个算法其实是因为LIS有NlogN的作法,把LCS转化为了LIS来做. 对于序列A{},B{},我们可以记录下来B中的每个元素在A中出现的位置,按顺序保存在一个新序列当中, 如果有多个位置按倒序写, ...

  5. (http请求+cookie)的交互流程

    如果步骤5携带的是过期的cookie或者是错误的cookie,那么将认证失败,返回至要求身份认证页面. 当前 Cookie 有两个版本:Version 0 和 Version 1.通过它们有两种设置响 ...

  6. CrateDB——全文搜索使用的是lucene,尚不知其底层实现

    CrateDB: The fast, scalable, easy to use SQL database with native full text search https://crate.io ...

  7. TCPL学习笔记:编写expand(s1, s2),将字符串s1中类似于a-z一类的速记符号在s2中扩充完整。可以处理大小写及字符,以及a-b-c, a-z0-9以及-a-z等多种情况。

    话不多说,看代码: #include <stdio.h> #include <stdlib.h> int main(void) { ] = "a-z0-9hahah- ...

  8. SVN 的搭建及使用(二)VisualSVN Server建立版本库,以及VisualSVN和TortoiseSVN的使用

    上一篇介绍了VisualSVN Server和TortoiseSVN的下载,安装,汉化.这篇介绍一下如何使用VisualSVN Server建立版本库,以及VisualSVN和TortoiseSVN的 ...

  9. C++友元函数实现

    友元函数是一种特殊的函数,它必须要在类中进行声明,但其本身并不是类的成员函数,但友元函数可以访问类的私有成员变量. 友元函数的好处: 1.实现类之间的数据共享 2.提高程序运行效率,方便编程 友元函数 ...

  10. mac brew安装使用卸载

    (一)安装 1.浏览器打开brew.sh,进入homebrew主页.找到install homebrew 的命令: /usr/bin/ruby -e "$(curl -fsSL https: ...