// 789428 KB for N = 24 #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 cnt[1 << MAX_N]{}; 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); ++cnt[val]; } if (n <= HALF) { for (int i = 0; i < 1 << n; ++i) { res[i][0] = cnt[i]; } /* [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) { res[i][0] = cnt[i | (topbit << (n - 1))]; } 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][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 { assert(false); 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'; } }