显示原始代码
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Read in = new Read();
int n = in.nextInt(), m = in.nextInt();
String[] f = new String[n];
int[] cnt = new int[m];
for (int i = 0; i < n; i++) {
f[i] = in.next();
}
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (f[i].charAt(j) == '1') {
cnt[j]++;
}
}
}
int res = n;
Map<Integer, Integer> mp = new HashMap<>();
for (int x : cnt) mp.put(x, mp.getOrDefault(x, 0) + 1);
if (!mp.containsKey(1))
System.out.println(n);
else {
while (mp.get(1) > 0) {
for (int j = 0; j < m; j++) {
if (cnt[j] == 1) {
mp.put(cnt[j], mp.get(cnt[j]) - 1);
res--;
for (int i = 0; i < n; i++) {
if (f[i].charAt(j) == '1') {
for (int k = 0; k < m; k++) {
if (f[i].charAt(k) == '1') {
mp.put(cnt[k], mp.get(cnt[k]) - 1);
cnt[k]--;
}
}
}
}
}
}
}
System.out.println(res);
}
}
static class Read {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
}