This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int B = 10;
array<int, 2> s[1<<B][1<<B][2];
int popcount[1<<B];
signed main() {
	cin.tie(0)->sync_with_stdio(0);
	for(int i = 0; i < (1<<B); ++i)
		popcount[i] = __builtin_popcount(i);
	
	int N, M; cin >> N >> M;
	int A[N] {}, c[M] {};
	for(int i = 0; i < N; ++i) {
		for(int j = 0; j < M; ++j) {
			int v; cin >> v;
			A[i] |= v << j;
			c[j] += v;
		}
		int x = A[i] >> B;
		for(int j = 0; j < (1<<B); ++j) {
			int v = popcount[~A[i] & j];
			if(v > s[x][j][0][0]) s[x][j][0] = {v, i};
			if(v > s[x][j][1][0]) swap(s[x][j][0], s[x][j][1]);
		}
	}
	for(int i = 0; i < N; ++i) {
		int ans {}, ext {}, x {};
		for(int j = 0; j < M; ++j) {
			int cur = c[j] - bool(A[i] & (1<<j));
			if(cur == N / 2) x |= 1<<j;
			if(cur  > N / 2) ++ext;
		}
		auto &k = s[A[i] >> B][x & ((1<<B) - 1)];
		if(k[1][1] == i) swap(k[0], k[1]);
		int y = x & ((1<<B) - 1);
		for(int j = 0; j < (1<<B); ++j)
			ans = max(ans, popcount[(x >> B) & ~j] + s[j][y][1][0]);
		if(k[1] < k[0]) swap(k[0], k[1]);
		cout << ans + ext << '\n';
	}
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |