专栏首页wymEducational Codeforces Round 44 (Rated for Div. 2) B. Switches and Lamps

Educational Codeforces Round 44 (Rated for Div. 2) B. Switches and Lamps

B. 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列的矩阵,n表示n个开关,m表示m盏灯

矩阵中1表示该开关能控制该灯,为0表示不能,问能否用n-1个开关控制m盏灯,若能输出YES,否则输出NO

题解:

就看每盏灯是否能被单独控制,即少了这个开关不行,如果每个开关都单独控制一盏灯,就NO,其他就YES

#include <bits/stdc++.h> #define maxn 2005  using namespace std; char a[maxn][maxn]; int v[maxn]; int n,s,t,m;  int main() {     cin>>n>>m;     for(int i=0;i<n;i++)scanf("%s",a[i]);      for(int j=0;j<m;j++)      { s=0; for(int i=0;i<n;i++)   if(a[i][j]-'0'==1)s++,t=i;    if(s==1) v[t]=1; }    for(int i=0;i<n;i++)     if(!v[i]) { printf("YES\n"); return 0;}     printf("NO\n"); return 0; }

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • hdu1010Tempter of the Bone

    The doggie found a bone in an ancient maze, which fascinated him a lot. However,...

    用户2965768
  • hdu1026 Ignatius and the Princess I(bfs+路径)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth...

    用户2965768
  • Codeforces Round #483 (Div. 2) B. Minesweeper

    One day Alex decided to remember childhood when computers were not too powerful ...

    用户2965768
  • golang net之http server

    在浏览器输入“http://127.0.0.1:8000”得到输出“Hi,Stranger,welcome”;输入“http://127.0.0.1:8000/...

    charlieroro
  • Code Forces 644A Parliament of Berland

    A. Parliament of Berland time limit per test1 second memory limit per test25...

    ShenduCC
  • Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) B. Bear and Blocks (技巧dp 难想)

    Limak is a little bear who loves to play. Today he is playing by destroying bloc...

    glm233
  • C++核心准则E.26:如果无法抛出异常,尽快进行失败处理​

    E.26: If you can't throw exceptions, consider failing fast

    面向对象思考
  • poj-1207 THE 3n+1 problem

    Problems in Computer Science are often classified as belonging to a certain clas...

    瑾诺学长
  • POJ 2398--Toy Storage(叉积判断,二分找点,点排序)

    Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...

    Enterprise_
  • Java字节码修改库ASM#ClassReader实现原理及源码分析

    ASM是Java中比较流行的用来读写字节码的类库,用来基于字节码层面对代码进行分析和转换。

    JavaEdge

扫码关注云+社区

领取腾讯云代金券