Source Code
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n,m;
    cin>>n>>m;

    vector<vector<char>>grid(n,vector<char>(m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>grid[i][j];
        }
    }

    set<int>st;
    for(int i=0;i<m;i++){
        int count=0,c=-1;
        for(int j=0;j<n;j++){
            count+=grid[j][i]=='1';
            if(grid[j][i]=='1'){
                c=j;
            }
        }
        if(count==1){
            st.insert(c);
        }
    }

    cout<<st.size();
}
Copy
Obada Discovers His Hearing Issues YazanIstatiyeh
GNU G++17
13 ms
1.8 MB
Accepted