제출 #739643

#제출 시각아이디문제언어결과실행 시간메모리
739643sidonCouncil (JOI23_council)C++17
100 / 100
3511 ms23632 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...