답안 #872357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872357 2023-11-13T00:54:59 Z MinaRagy06 Council (JOI23_council) C++17
0 / 100
764 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int a[100'005], cnt[20], dp[21][1 << 20][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][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][msk][j] += dp[i + 1][msk][j - 1];
					dp[i][msk][j] += dp[i + 1][msk ^ (1 << i)][j];
				} else {
					dp[i][msk][j] += dp[i + 1][msk][j];
					dp[i][msk][j] += dp[i + 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;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 1 ms 4560 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Runtime error 764 ms 1048576 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 1 ms 4560 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Runtime error 764 ms 1048576 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 23 ms 9552 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 23 ms 9552 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 23 ms 9552 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 23 ms 9552 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 1 ms 4560 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Runtime error 764 ms 1048576 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -