Submission #1332865

#TimeUsernameProblemLanguageResultExecution timeMemory
1332865gelastropodCouncil (JOI23_council)C++20
33 / 100
4094 ms16712 KiB
#pragma GCC optimize("O3,inline")
#include <bits/stdc++.h>
#include <bit>
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; 
	unsigned int e = 0, f = 0; cin >> N >> M;
	vector<unsigned 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 (unsigned int i = 0; i < (1LL << M); i++) {
		int ans = 0, ans1 = 0;
		for (int j = 0; j < N; j++) {
			int crnt = popcount(f & ((e & (~(i & vals[j]))) | ((~e) & (~i) & (~vals[j]))));
			if (crnt > ans1) ans1 = crnt;
			if (ans < ans1) swap(ans, ans1);
		}
		precompp[i] = { ans, ans1 };
	}
	for (int i = 0; i < N; i++) {
		int crnt = popcount(f & (~vals[i]));
		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...