제출 #1332856

#제출 시각아이디문제언어결과실행 시간메모리
1332856gelastropodCouncil (JOI23_council)C++20
16 / 100
4091 ms2788 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);
	}
	for (int i = 0; i < N; i++) {
		int ans = 0;
		for (int j = 0; j < N; j++) {
			if (i == j) continue;
			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)) && (vals[j] & (1LL << k))) crnt--;
				}
				else if ((!(vals[i] & (1LL << k))) && (!(vals[j] & (1LL << k)))) crnt++;
			}
			ans = max(ans, crnt);
		}
		cout << ans + 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...