Submission #1077788

# Submission time Handle Problem Language Result Execution time Memory
1077788 2024-08-27T09:08:57 Z vjudge1 Council (JOI23_council) C++17
6 / 100
341 ms 27404 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; 
		}
		//~ if (i == 3) {
			//~ cerr << "msk: " << mask << endl; 
		//~ }
	}
	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; 
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 75 ms 25052 KB Output is correct
6 Correct 57 ms 25088 KB Output is correct
7 Correct 63 ms 24916 KB Output is correct
8 Correct 79 ms 24912 KB Output is correct
9 Correct 114 ms 25108 KB Output is correct
10 Correct 59 ms 25068 KB Output is correct
11 Correct 80 ms 24920 KB Output is correct
12 Correct 102 ms 24920 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 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 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 1 ms 344 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 344 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 -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 75 ms 25052 KB Output is correct
6 Correct 57 ms 25088 KB Output is correct
7 Correct 63 ms 24916 KB Output is correct
8 Correct 79 ms 24912 KB Output is correct
9 Correct 114 ms 25108 KB Output is correct
10 Correct 59 ms 25068 KB Output is correct
11 Correct 80 ms 24920 KB Output is correct
12 Correct 102 ms 24920 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 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 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 1 ms 344 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 344 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 -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 96 ms 18512 KB Output is correct
3 Correct 81 ms 18512 KB Output is correct
4 Correct 57 ms 17980 KB Output is correct
5 Correct 95 ms 18512 KB Output is correct
6 Correct 63 ms 18004 KB Output is correct
7 Correct 88 ms 18512 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 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 432 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 96 ms 18512 KB Output is correct
3 Correct 81 ms 18512 KB Output is correct
4 Correct 57 ms 17980 KB Output is correct
5 Correct 95 ms 18512 KB Output is correct
6 Correct 63 ms 18004 KB Output is correct
7 Correct 88 ms 18512 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 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 432 KB Output is correct
16 Correct 0 ms 348 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 341 ms 27404 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 96 ms 18512 KB Output is correct
3 Correct 81 ms 18512 KB Output is correct
4 Correct 57 ms 17980 KB Output is correct
5 Correct 95 ms 18512 KB Output is correct
6 Correct 63 ms 18004 KB Output is correct
7 Correct 88 ms 18512 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 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 432 KB Output is correct
16 Correct 0 ms 348 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 341 ms 27404 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 96 ms 18512 KB Output is correct
3 Correct 81 ms 18512 KB Output is correct
4 Correct 57 ms 17980 KB Output is correct
5 Correct 95 ms 18512 KB Output is correct
6 Correct 63 ms 18004 KB Output is correct
7 Correct 88 ms 18512 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 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 432 KB Output is correct
16 Correct 0 ms 348 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 341 ms 27404 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 75 ms 25052 KB Output is correct
6 Correct 57 ms 25088 KB Output is correct
7 Correct 63 ms 24916 KB Output is correct
8 Correct 79 ms 24912 KB Output is correct
9 Correct 114 ms 25108 KB Output is correct
10 Correct 59 ms 25068 KB Output is correct
11 Correct 80 ms 24920 KB Output is correct
12 Correct 102 ms 24920 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 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 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 1 ms 344 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 344 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 -