제출 #1332863

#제출 시각아이디문제언어결과실행 시간메모리
1332863gelastropodCouncil (JOI23_council)C++20
6 / 100
4094 ms16708 KiB
#pragma GCC optimize("O3,inline")
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N, M, a, val1 = 0, e = 0, f = 0; cin >> N >> M;
	vector<int> vals(N, 0);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> a;
			if (a) vals[i] += (1LL << j);
		}
	}
	for (int i = 0; i < M; i++) {
		int crnt = 0;
		for (int j = 0; j < N; j++)
			if (vals[j] & (1LL << i)) crnt++;
		if (crnt > N / 2 + 1) val1++;
		else if (crnt == N / 2 + 1) e += (1LL << i);
		if (crnt >= N / 2 && crnt <= N / 2 + 1) f += (1LL << i);
	}
	vector<pair<int, int>> precompp((1LL << M), { 0, 0 });
	for (int i = 0; i < (1LL << M); i++) {
		int ans = 0, ans1 = 0;
		for (int j = 0; j < N; j++) {
			int crnt = 0;
			for (int k = 0; k < M; k++) {
				if (!(f & (1LL << k))) continue;
				if (e & (1LL << k)) {
					crnt++;
					if ((i & (1LL << k)) && (vals[j] & (1LL << k))) crnt--;
				}
				else if ((!(i & (1LL << k))) && (!(vals[j] & (1LL << k)))) crnt++;
			}
			if (crnt > ans1) ans1 = crnt;
			if (ans < ans1) swap(ans, ans1);
		}
		precompp[i] = { ans, ans1 };
	}
	for (int i = 0; i < N; i++) {
		int crnt = 0;
		for (int k = 0; k < M; k++) {
			if (!(f & (1LL << k))) continue;
			if (e & (1LL << k)) {
				crnt++;
				if (vals[i] & (1LL << k)) crnt--;
			}
			else if (!(vals[i] & (1LL << k))) crnt++;
		}
		if (precompp[vals[i]].first == crnt) cout << precompp[vals[i]].second + val1 << '\n';
		else cout << precompp[vals[i]].first + val1 << '\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...