Source Code
#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    string s[n];
    int c[n] ={0};
    for (int i=0;i<n;i++){
        cin>>s[i];
    }
    for (int i=0;i<m;i++){
        int sum = 0;
        int ind;
        for (int j=0;j<n;j++){
            sum+=s[j][i]-'0';
            if (s[j][i]=='1') ind = j;
        }
        if (sum==1){
            c[ind] = 1;
        }
    }
    int counter =0;
    for (int i=0;i<n;i++){
        if (c[i]==1) counter++;
    }
    cout<<counter<<endl;
    return 0;
}
Copy
Obada Discovers His Hearing Issues Mohamedmaher
GNU G++17
32 ms
2.8 MB
Accepted