Source Code
#include <iostream>
using namespace std;

int main() {
	int n;
	int m;
	cin >> n;
	cin >> m;
	const int size = n;
	string* arr = new string[size];

	for (int i = 0;i < n;i++)
		cin >> arr[i];

	bool* flag = new bool[size];

	for (int i = 0;i < size;i++)
		flag[i] = false;

	int count = 0;

	for (int i = 0;i <m;i++)
	{
		int val = 0;
		bool* flag2 = new bool[size];

		for (int i = 0;i < size;i++)
			flag2[i] = false;

		for (int j = 0;j < n;j++)
		{
			if (arr[j][i] == '1') {
				val++;
				flag2[j] = true;
			}
		}

		if (val == 1)
		{
			for (int j = 0;j < n;j++) {
				if (flag2[j])
				{
					if (!flag[j]) {
						count++;
						flag[j] = true;
					}
					break;
				}
					
			}
		}
	}
	
	cout << count;
}
Copy
Obada Discovers His Hearing Issues Qusay
GNU G++17
19 ms
3.8 MB
Accepted