Source Code
#include <iostream>
#include <string>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	string binary[1000];
	int freq[1000] = {0};
	
	for (int i=0; i<n; i++) {
		cin >> binary[i];
	}
	int temp, tempsum;
	for (int i=0; i<m; i++) {
		tempsum = 0;
		for (int j=0; j<n; j++) {
			if (binary[j][i] == '1') {
				temp = j;
				tempsum += 1;
			}
		}
		if (tempsum == 1) {
			freq[temp]++;
		}
	}
	
	int ans = 0;
	for (int i = 0; i<n; i++) {
		if (freq[i] > 0)
			ans++;
	}
	cout << ans << endl;
}
Copy
Obada Discovers His Hearing Issues Dana
GNU G++17
18 ms
2.7 MB
Accepted