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 

题意: 给你n*m盏灯,i行j列1代表i可以控制灯j的开关,0代表不可以,问是否可以去掉一行剩余的灯还是可以亮着。如果可以输出YES,不可以输出NO

遍历每一行,如果去掉哪行时剩余的每列有一列和不为0,那么证明可以去掉该行,输出YES
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = *1e3 + ;
const int mod = 1e9 + ;
typedef long long ll;
char mapn[maxn][maxn];
ll sum[maxn];
int main(){
std::ios::sync_with_stdio(false);
ll n, m;
while( cin >> n >> m ) {
memset( sum, , sizeof(sum) );
for( ll i = ; i < n; i ++ ) {
for( ll j = ; j < m; j ++ ) {
cin >> mapn[i][j];
sum[j] += mapn[i][j] - '';
}
}
bool flg = false;
for( ll i = ; i < n; i ++ ) {
bool flag = true;
for( ll j = ; j < m; j ++ ) {
if( sum[j] - ( mapn[i][j] - '' ) == ) {
flag = false;
break;
}
}
if( flag ) {
cout << "YES" << endl;
flg = true;
break;
}
}
if( !flg ) {
cout << "NO" << endl;
}
}
return ;
}

最新文章

  1. Metasploit爆破tcpwrapped服务
  2. [转]iOS开发中@property的属性weak nonatomic strong readonly等介绍
  3. phpMyAdmin的配置
  4. isInstance和isAssignableFrom的用法
  5. 套汇问题 Floyd
  6. Silverlight学习之初始化参数
  7. 怎样衡量一个组员在团队中的Performance
  8. android学习日记13--数据存储之SQLite
  9. Spring AOP实现方式一【附源码】
  10. 利用ACE 自己实现的线程池
  11. phpcms 缓存
  12. 在Mac电脑上为Dash制作docSet文档
  13. 使用cl编译C/C++
  14. (转)Python-正则表达式
  15. python下载及安装
  16. v4l2框架分析
  17. java安全管理器SecurityManager介绍
  18. react用class关键字来创建组件
  19. Java实验6
  20. Contest2071 - 湖南多校对抗赛(2015.03.28)

热门文章

  1. 【游记】NOIP2019前传
  2. 【游记】NOIP2019初赛
  3. SpringBoot:Web开发
  4. 《深入理解Java虚拟机》-Java代码是如何运行的
  5. 从IDEA角度来看懂UML图
  6. 100天搞定机器学习|day39 Tensorflow Keras手写数字识别
  7. win10文件备份、文件同步方案
  8. ansible之变量
  9. var let及const
  10. Homebrew 安装 Docker Desktop for Mac