985B - Switches and Lamps - CodeForces Solution


implementation *1200

Please click on ads to support us..

Python Code:

def solve():
        n, m = map(int, input().split())
        s = []
        cnt = [0]*m

    for i in range(n):
        s.append(list(input().strip()))
        for j in range(m):
            if s[i][j] == '1':
                cnt[j] += 1 
    for i in range(n):
        ok = True
                for j in range(m):
            if s[i][j] == '1' and cnt[j] == 1:
                ok = False
        if ok == True:             print("YES")
            return

        print("NO")

solve()

C++ Code:

/*
 * @author islam Mohamed Abououf
 */

#include "bits/stdc++.h"
using namespace std ;
#define ll long long
#define cin(v) for(auto &el : (v)) cin >> el
#define cout(v) for(auto &el : (v)) cout << el << ' ' ; cout << nl ;
#define Tc int t ; cin>>t ;while(t--)
#define all(vc) vc.begin() , (vc).end()
#define vi vector<int>
#define vii vector<pair<int , int>>
#define vvi vector<vector<int>>
#define mpii map<int,int>
#define mpll map<ll,ll>
#define vll  vector<ll>
#define nl '\n'
#define yes cout << "YES" << nl ;
#define no cout << "NO" << nl ;
#define _ ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);


ll mod = 1e9+7;
int OO = 1e9;
ll N = 2e5+5 ;
vector<bool> isPrime(N,true);
set<ll> primes;
vi freq(N) ;

int get_divisors(ll num){
    set<ll> st ;
    for (ll i = 2; i*i <= num; ++i) {
        if(num%i == 0){
            st.insert(i) ;
            st.insert(num/i);
        }
    }
    return (int) st.size();
}
void sieve(){
    isPrime[0]= false ;
    isPrime[1]= false ;
    for (int i = 2; i <N ; ++i) {
        if(isPrime[i]){
            primes.insert(i) ;
            for (int j = i+i; j<N ; j+=i) {
                isPrime[j]= false ;
            }
        }
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}
ll fact(ll a){
    if(a==1)
        return a ;
    return a * fact(a-1) ;
}
ll lcm(ll a, ll b){
    return a/gcd(a,b)*b;
}
vector<string> switches ;
ll n,m;
vector<bool> dep(2005 , true) ;
void validate(){
    for (int i = 0; i <m; ++i) {
        int sum =0 , x = 0;
        for (int j = 0; j < n; ++j) {
            if(switches[j][i]=='1'){
                sum++ ;
                x = j ;
            }
        }
        if(sum==1) dep[x] = false;
    }
}
// 1 1
// 2 1
// 4 -1
// 5 1

void answer() {
    cin >> n>>m;
    for (int i = 0; i < n; ++i) {
        string x;
        cin >> x;
        switches.push_back(x);
    }
    validate() ;
    for (int i = 0; i < n; ++i) {
        if(dep[i]) {
            yes return;
        }
    }
    no
}

int main() {
    _
//    Tc{
//        answer() ;
//    }
    answer();

}
		 			  	 	    	 	 		  	   		


Comments

Submit
0 Comments
More Questions

678A - Johny Likes Numbers
1699C - The Third Problem
1697D - Guess The String
754B - Ilya and tic-tac-toe game
760A - Petr and a calendar
1573A - Countdown
166A - Rank List
1631B - Fun with Even Subarrays
727A - Transformation from A to B
822B - Crossword solving
1623A - Robot Cleaner
884B - Japanese Crosswords Strike Back
862B - Mahmoud and Ehab and the bipartiteness
429A - Xor-tree
1675C - Detective Task
950A - Left-handers Right-handers and Ambidexters
672B - Different is Good
1C - Ancient Berland Circus
721A - One-dimensional Japanese Crossword
1715B - Beautiful Array
60B - Serial Time
453A - Little Pony and Expected Maximum
1715A - Crossmarket
1715C - Monoblock
1512C - A-B Palindrome
1679B - Stone Age Problem
402A - Nuts
792A - New Bus Route
221A - Little Elephant and Function
492C - Vanya and Exams