Submission #1213966

#TimeUsernameProblemLanguageResultExecution timeMemory
1213966k1r1t0Council (JOI23_council)C++20
6 / 100
249 ms16864 KiB
#include <bits/stdc++.h>

using namespace std;
#define int long long

const int N = 310000;
const int M = 20;

int n, m, a[N], c[M], dp[1 << M][2];

bool comp(int msk, int x, int y) {
	if (x == 0) return false;
	if (y == 0) return true;
	int c1 = __builtin_popcount(msk & ~a[x]);
	int c2 = __builtin_popcount(msk & ~a[y]);
	return c1 > c2;
}

void upd(int msk, int k) {
	if (comp(msk, k, dp[msk][0])) {
		dp[msk][1] = dp[msk][0];
		dp[msk][0] = k;
	} else if (comp(msk, k, dp[msk][1])) {
		dp[msk][1] = k;
	}
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			int t; cin >> t;
			c[j] += t;
			a[i] |= (t << j);
		}
		upd(a[i], i);
	}
	for (int i = 0; i < m; i++)
		for (int msk = 0; msk < (1 << m); msk++)
			if (msk & (1 << i)) {
				upd(msk ^ (1 << i), dp[msk][0]);
				upd(msk ^ (1 << i), dp[msk][1]);
			}
	for (int i = 0; i < m; i++)
		for (int msk = 0; msk < (1 << m); msk++)
			if (!(msk & (1 << i))) {
				upd(msk ^ (1 << i), dp[msk][0]);
				upd(msk ^ (1 << i), dp[msk][1]);
			}
	for (int i = 1; i <= n; i++) {
		int msk = 0, ans = 0;
		for (int j = 0; j < m; j++) {
			int t = c[j];
			if (a[i] & (1 << j))
				t--;
			if (t > n / 2)
				ans++;
			if (t == n / 2)
				msk |= (1 << j);
		}
		if (dp[msk][0] == i)
			ans += __builtin_popcount(msk & ~a[dp[msk][1]]);
		else
			ans += __builtin_popcount(msk & ~a[dp[msk][0]]);
		cout << ans << '\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...