codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

985B.md (1971B)


      1 Source: https://codeforces.com/problemset/problem/985/B
      2 
      3 B. Switches and Lamps
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 Initially all *m* lamps are turned off.
     24 
     25 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.
     26 
     27 It is guaranteed that if you push all *n* switches then all *m* lamps will be turned on.
     28 
     29 Your think that you have too many switches and you would like to ignore one of them.
     30 
     31 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.
     32 
     33 Input
     34 
     35 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.
     36 
     37 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.
     38 
     39 It is guaranteed that if you press all *n* switches all *m* lamps will be turned on.
     40 
     41 Output
     42 
     43 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.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 4 5  
     51 10101  
     52 01000  
     53 00111  
     54 10000
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 YES
     61 ```
     62 
     63 Input
     64 
     65 ```
     66 4 5  
     67 10100  
     68 01000  
     69 00110  
     70 00101
     71 ```
     72 
     73 Output
     74 
     75 ```
     76 NO
     77 ```