Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int n, m, fr[2001];
string s[2001];
int main() {
cin >> n >> m;
for(int i = 0; i < n; ++i) {
cin >> s[i];
for(int j = 0; j < m; ++j)
fr[j] += (s[i][j] - '0');
}
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j)
fr[j] -= (s[i][j] - '0');
bool ok = true;
for(int j = 0; j < m; ++j)
if(fr[j] == 0) {
ok = false;
break;
}
if(ok) {
puts("YES");
return 0;
}
for(int j = 0; j < m; ++j)
fr[j] += (s[i][j] - '0');
}
puts("NO");
return 0;
}
Copy The Code &
Try With Live Editor
Input
4 5
10101
01000
00111
10000
10101
01000
00111
10000
Output
YES
Demonstration
Codeforces Solution-B. Switches and Lamps-Solution in C, C++, Java, Python,Switches and Lamps,Codeforces Solution