// 789428 KB for N = 24 #include #include #include #include constexpr int MAX_N = 24; constexpr int HALF = MAX_N / 2; constexpr int MAX_SIZE = 7; int res[1 << MAX_N][MAX_SIZE]{}; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m, k; std::cin >> n >> m >> k; for (int i = 0; i < m; ++i) { std::string S; std::cin >> S; int val = 0; for (int j = 0; j < n; ++j) val |= ((S[j] - '0') << j); ++res[val][0]; } if (k <= HALF) { assert(k <= MAX_SIZE); /* [1,1] [1,x] */ for (int B = 1; B < 1 << n; B <<= 1) { for (int L = 0; L < 1 << n; L += 2 * B) { for (int p = 0; p < B; ++p) { int *u = res[L + p], *v = res[L + B + p]; for (int t = k; t--;) { int tmp = u[t]; u[t] = tmp + v[t]; v[t] = tmp + (t ? v[t - 1] : 0); } } } } std::vector g(m + 1, n); for (int T = 0; T < 1 << n; ++T) { int T_size = __builtin_popcount(T); int f_T = m; for (int i = 0; i < k; ++i) f_T -= res[T][i]; g[f_T] = std::min(g[f_T], T_size); } for (int i = m - 1; i >= 0; --i) g[i] = std::min(g[i], g[i + 1]); for (int i = 1; i <= m; ++i) std::cout << g[i] << '\n'; } else { const int r = n - k + 1; assert(r <= MAX_SIZE); /* [x,x] [x,1] */ for (int B = 1; B < 1 << n; B <<= 1) { for (int L = 0; L < 1 << n; L += 2 * B) { for (int p = 0; p < B; ++p) { int *u = res[L + p], *v = res[L + B + p]; for (int t = r; t-- > 1;) { u[t] = u[t - 1] + v[t - 1]; v[t] += u[t - 1]; } u[0] = 0; } } } std::vector g(m + 1, n); for (int T = 0; T < 1 << n; ++T) { int T_size = __builtin_popcount(T); int f_T = 0; for (int i = 0; i < r; ++i) f_T += res[T][i]; g[f_T] = std::min(g[f_T], T_size); } for (int i = m - 1; i >= 0; --i) g[i] = std::min(g[i], g[i + 1]); for (int i = 1; i <= m; ++i) std::cout << g[i] << '\n'; } }