제출 #1335136

#제출 시각아이디문제언어결과실행 시간메모리
1335136gelastropodCouncil (JOI23_council)C++20
6 / 100
32 ms3296 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;
	unsigned int fl = (1LL << M) - 1;
	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<int> minpc((1LL << M), INT_MIN);
	for (int i = 0; i < N; i++) minpc[fl ^ vals[i]] = popcount(fl ^ vals[i]);
	for (int i = (1LL << M) - 1; i >= 0; i--) {
		for (int j = 0; j < M; j++) {
			if (!(i & (1LL << j))) continue;
			minpc[i ^ (1LL << j)] = max(minpc[i ^ (1LL << j)], max(minpc[i], (int)INT_MIN + 1) - 1);
		}
	}
	for (int i = 0; i < (1LL << M); i++) {
		for (int j = 0; j < M; j++) {
			if (i & (1LL << j)) continue;
			minpc[i ^ (1LL << j)] = max(minpc[i ^ (1LL << j)], minpc[i]);
		}
	}
	for (int i = 0; i < N; i++) {
		int crnt = popcount((~vals[i]) & _e), crnt1 = 0;
		unsigned int g = (~(vals[i] ^ _e)) & f;
		int goofy = popcount(g & vals[i]);
		crnt1 = minpc[g];
		cout << val1 + crnt + crnt1 << '\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...