답안 #1077791

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077791 2024-08-27T09:10:21 Z NeroZein Council (JOI23_council) C++17
6 / 100
351 ms 25092 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> a(n + 1, vector<int>(m));
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> a[i][j];
		}
	}
	vector<int> attainable(1 << m);
	vector<int> attainable2(1 << m);
	for (int i = 1; i <= n; ++i) {
		int mask = 0;
		for (int j = 0; j < m; ++j) {
			mask |= (1 << j) * a[i][j];
		}
		if (!attainable[mask]) {
			attainable[mask] = i;			
		} else {
			attainable2[mask] = i; 
		}
	}
	
	for (int j = 0; j < m; ++j) {
		for (int mask = 0; mask < (1 << m); ++mask) {
			if (!(mask >> j & 1)) {
				continue; 
			}
			int cfrom = attainable[mask];
			int cfrom2 = attainable2[mask];
			
			if (cfrom == 0) {
				attainable[mask] = attainable[mask ^ (1 << j)];
				attainable2[mask] = attainable2[mask ^ (1 << j)];
			} else if (cfrom2 == 0) {
				attainable2[mask] = attainable[mask ^ (1 << j)];
			}
			assert(attainable[mask] == 0 || attainable[mask] != attainable2[mask]);
		}
	}
	vector<pair<int, int>> dp(1 << m);
	vector<pair<int, int>> dp2(1 << m);
	
	for (int mask = 0; mask < (1 << m); ++mask) {
		if (attainable[mask]) {
			dp[mask] = {mask, attainable[mask]};			
		}
		if (attainable2[mask]) {
			dp2[mask] = {mask, attainable2[mask]};			
		}
	}
	
	for (int j = 0; j < m; ++j) {
		for (int mask = 0; mask < (1 << m); ++mask) {
			if (mask >> j & 1) {
				continue; 
			}
			if (dp[mask | (1 << j)].second && dp[mask | (1 << j)].second != dp[mask].second && (!dp[mask].second || __builtin_popcount(dp[mask | (1 << j)].first) < __builtin_popcount(dp[mask].first))) {
				swap(dp[mask], dp2[mask]);
				dp[mask] = dp[mask | (1 << j)];
				if (dp2[mask | (1 << j)].second && dp2[mask | (1 << j)].second != dp2[mask].second && (!dp2[mask].second || __builtin_popcount(dp2[mask | (1 << j)].first) < __builtin_popcount(dp2[mask].first))) {
					dp2[mask] = dp2[mask | (1 << j)];
				}
			} else if (dp[mask | (1 << j)].second && dp[mask | (1 << j)].second != dp2[mask].second && dp[mask | (1 << j)].second != dp[mask].second && (!dp2[mask].second || __builtin_popcount(dp[mask | (1 << j)].first) < __builtin_popcount(dp2[mask].first))) {
				dp2[mask] = dp[mask | (1 << j)];
			}
		}
	}
	
	vector<int> cnt(m); 
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < m; ++j) {
			cnt[j] += a[i][j];
		}
	}
	
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < m; ++j) {
			cnt[j] -= a[i][j];
		}
	
		int ans = 0; 
		int mask = 0; 
		for (int j = 0; j < m; ++j) {
			if (cnt[j] != n / 2) {
				mask |= (1 << j); 
			}
			if (cnt[j] > n / 2) {
				ans++; 
			}
		}
		if (dp[mask].second != i) {
			ans += m - __builtin_popcount(dp[mask].first);
		} else {
			ans += m - __builtin_popcount(dp2[mask].first); 
		}
		cout << ans << '\n'; 
		for (int j = 0; j < m; ++j) {
			cnt[j] += a[i][j];
		}
	}
	
	return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 59 ms 24952 KB Output is correct
6 Correct 86 ms 25092 KB Output is correct
7 Correct 58 ms 24916 KB Output is correct
8 Correct 68 ms 24848 KB Output is correct
9 Correct 116 ms 24916 KB Output is correct
10 Correct 87 ms 24912 KB Output is correct
11 Correct 78 ms 24920 KB Output is correct
12 Correct 103 ms 25004 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Incorrect 1 ms 604 KB Output isn't correct
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 59 ms 24952 KB Output is correct
6 Correct 86 ms 25092 KB Output is correct
7 Correct 58 ms 24916 KB Output is correct
8 Correct 68 ms 24848 KB Output is correct
9 Correct 116 ms 24916 KB Output is correct
10 Correct 87 ms 24912 KB Output is correct
11 Correct 78 ms 24920 KB Output is correct
12 Correct 103 ms 25004 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Incorrect 1 ms 604 KB Output isn't correct
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 93 ms 17420 KB Output is correct
3 Correct 87 ms 17388 KB Output is correct
4 Correct 69 ms 17372 KB Output is correct
5 Correct 100 ms 17368 KB Output is correct
6 Correct 74 ms 17220 KB Output is correct
7 Correct 99 ms 17380 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 93 ms 17420 KB Output is correct
3 Correct 87 ms 17388 KB Output is correct
4 Correct 69 ms 17372 KB Output is correct
5 Correct 100 ms 17368 KB Output is correct
6 Correct 74 ms 17220 KB Output is correct
7 Correct 99 ms 17380 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 351 ms 22080 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 93 ms 17420 KB Output is correct
3 Correct 87 ms 17388 KB Output is correct
4 Correct 69 ms 17372 KB Output is correct
5 Correct 100 ms 17368 KB Output is correct
6 Correct 74 ms 17220 KB Output is correct
7 Correct 99 ms 17380 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 351 ms 22080 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 93 ms 17420 KB Output is correct
3 Correct 87 ms 17388 KB Output is correct
4 Correct 69 ms 17372 KB Output is correct
5 Correct 100 ms 17368 KB Output is correct
6 Correct 74 ms 17220 KB Output is correct
7 Correct 99 ms 17380 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 351 ms 22080 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 59 ms 24952 KB Output is correct
6 Correct 86 ms 25092 KB Output is correct
7 Correct 58 ms 24916 KB Output is correct
8 Correct 68 ms 24848 KB Output is correct
9 Correct 116 ms 24916 KB Output is correct
10 Correct 87 ms 24912 KB Output is correct
11 Correct 78 ms 24920 KB Output is correct
12 Correct 103 ms 25004 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Incorrect 1 ms 604 KB Output isn't correct
43 Halted 0 ms 0 KB -