Submission #872361

# Submission time Handle Problem Language Result Execution time Memory
872361 2023-11-13T01:00:44 Z MinaRagy06 Council (JOI23_council) C++17
0 / 100
2 ms 4956 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int a[300'005], cnt[21], dp[2][1 << 21][21];
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, m;
	cin >> n >> m;
	int mx = 1 << m;
	for (int i = 0; i < n; i++) {
		for (int j = 0, x; j < m; j++) {
			cin >> x;
			a[i] |= x << j;
			cnt[j] += x;
		}
		dp[m & 1][a[i]][0]++;
	}
	for (int i = m - 1; i >= 0; i--) {
		for (int msk = 0; msk < mx; msk++) {
			for (int j = 0; j <= m; j++) {
				if ((msk >> i) & 1) {
					if (j - 1 >= 0) dp[i & 1][msk][j] += dp[(i + 1) & 1][msk][j - 1];
					dp[i & 1][msk][j] += dp[(i + 1) & 1][msk ^ (1 << i)][j];
				} else {
					dp[i & 1][msk][j] += dp[(i + 1) & 1][msk][j];
					dp[i & 1][msk][j] += dp[(i + 1) & 1][msk ^ (1 << i)][j];
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) cnt[j] -= (a[i] >> j) & 1;
		int msk = 0, gud = 0;
		for (int j = 0; j < m; j++) {
			if (cnt[j] == n / 2) {
				msk |= 1 << j;
			} else if (cnt[j] > n / 2) {
				gud++;
			}
		}
		int cur = __builtin_popcount(a[i] & msk), mn = m;
		for (int k = 0; k <= m; k++) {
			if (dp[0][msk][k] > 1 || (dp[0][msk][k] == 1 && cur != k)) {
				mn = k;
				break;
			}
		}
		cout << gud + __builtin_popcount(msk) - mn << '\n';
		for (int j = 0; j < m; j++) cnt[j] += (a[i] >> j) & 1;
	}
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Incorrect 2 ms 4956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Incorrect 2 ms 4956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Incorrect 2 ms 4956 KB Output isn't correct
3 Halted 0 ms 0 KB -