#include #include #include #include constexpr int MAX_N = 24; constexpr int HALF = MAX_N / 2; constexpr int MAX_SIZE = HALF; int res[1 << (MAX_N - 1)][MAX_SIZE]{}; int f[1 << MAX_N]{}; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m, k; std::cin >> n >> m >> k; std::vector S(m); for (int i = 0; i < m; ++i) { std::cin >> S[i]; } if (n <= HALF) { for (const auto &s_str : S) { int s = 0; for (int i = 0; i < n; ++i) s |= (s_str[i] - '0') << i; ++res[s][0]; } /* [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'; return 0; } if (k <= HALF) { /* [1,1] [1,x] */ for (int i = 0; i < 1 << n; ++i) { f[i] = m; } for (int topbit : { 0, 1 }) { for (int i = 0; i < 1 << (n - 1); ++i) { for (int j = 0; j < HALF; ++j) res[i][j] = 0; } for (const auto &s_str : S) { int s = 0; for (int i = 0; i < n; ++i) s |= (s_str[i] - '0') << i; if ((s >> (n - 1)) == topbit) { ++res[s & ~(1 << (n - 1))][0]; } } for (int B = 1; B < 1 << (n - 1); B <<= 1) { for (int L = 0; L < 1 << (n - 1); 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); } } } } if (topbit == 0) { for (int T = 0; T < 1 << n; ++T) { for (int i = 0; i < k; ++i) { f[T] -= res[T & ~(1 << (n - 1))][i]; } } } else { for (int T = 0; T < 1 << n; ++T) { if (T >> (n - 1)) { for (int i = 0; i < k - 1; ++i) { f[T] -= res[T & ~(1 << (n - 1))][i]; } } else { for (int i = 0; i < k; ++i) { f[T] -= res[T][i]; } } } } } std::vector g(m + 1, n); for (int T = 0; T < 1 << n; ++T) { int T_size = __builtin_popcount(T); 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; /* [x,x] [x,1] */ for (int topbit : { 0, 1 }) { for (int i = 0; i < 1 << (n - 1); ++i) { for (int j = 0; j < HALF; ++j) res[i][j] = 0; } for (const auto &s_str : S) { int s = 0; for (int i = 0; i < n; ++i) s |= (s_str[i] - '0') << i; if ((s >> (n - 1)) == topbit) { ++res[s & ~(1 << (n - 1))][0]; } } for (int B = 1; B < 1 << (n - 1); B <<= 1) { for (int L = 0; L < 1 << (n - 1); 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; } } } if (topbit == 0) { for (int T = 0; T < 1 << n; ++T) { for (int i = 0; i < r - 1; ++i) { f[T] += res[T & ~(1 << (n - 1))][i]; } } } else { for (int T = 0; T < 1 << n; ++T) { if (T >> (n - 1)) { for (int i = 0; i < r; ++i) { f[T] += res[T & ~(1 << (n - 1))][i]; } } else { for (int i = 0; i < r - 1; ++i) { f[T] += res[T][i]; } } } } } std::vector g(m + 1, n); for (int T = 0; T < 1 << n; ++T) { int T_size = __builtin_popcount(T); 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'; } }