#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
int a[n]{}, cnt[m]{}, mx = 1 << m, dp[m + 1][mx][m + 1]{};
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 |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
2908 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Runtime error |
594 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
2908 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Runtime error |
594 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
56 ms |
3376 KB |
Output is correct |
3 |
Correct |
39 ms |
3172 KB |
Output is correct |
4 |
Correct |
32 ms |
2724 KB |
Output is correct |
5 |
Correct |
42 ms |
3152 KB |
Output is correct |
6 |
Correct |
31 ms |
2644 KB |
Output is correct |
7 |
Correct |
47 ms |
3604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 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 |
600 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 |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
56 ms |
3376 KB |
Output is correct |
3 |
Correct |
39 ms |
3172 KB |
Output is correct |
4 |
Correct |
32 ms |
2724 KB |
Output is correct |
5 |
Correct |
42 ms |
3152 KB |
Output is correct |
6 |
Correct |
31 ms |
2644 KB |
Output is correct |
7 |
Correct |
47 ms |
3604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 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 |
600 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 |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
158 ms |
8352 KB |
Output is correct |
21 |
Correct |
143 ms |
7548 KB |
Output is correct |
22 |
Correct |
141 ms |
7504 KB |
Output is correct |
23 |
Correct |
135 ms |
8792 KB |
Output is correct |
24 |
Correct |
126 ms |
8532 KB |
Output is correct |
25 |
Correct |
146 ms |
8484 KB |
Output is correct |
26 |
Correct |
159 ms |
8528 KB |
Output is correct |
27 |
Correct |
1 ms |
856 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
404 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
452 KB |
Output is correct |
35 |
Correct |
1 ms |
860 KB |
Output is correct |
36 |
Correct |
1 ms |
860 KB |
Output is correct |
37 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
860 KB |
Output is correct |
45 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
56 ms |
3376 KB |
Output is correct |
3 |
Correct |
39 ms |
3172 KB |
Output is correct |
4 |
Correct |
32 ms |
2724 KB |
Output is correct |
5 |
Correct |
42 ms |
3152 KB |
Output is correct |
6 |
Correct |
31 ms |
2644 KB |
Output is correct |
7 |
Correct |
47 ms |
3604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 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 |
600 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 |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
158 ms |
8352 KB |
Output is correct |
21 |
Correct |
143 ms |
7548 KB |
Output is correct |
22 |
Correct |
141 ms |
7504 KB |
Output is correct |
23 |
Correct |
135 ms |
8792 KB |
Output is correct |
24 |
Correct |
126 ms |
8532 KB |
Output is correct |
25 |
Correct |
146 ms |
8484 KB |
Output is correct |
26 |
Correct |
159 ms |
8528 KB |
Output is correct |
27 |
Correct |
1 ms |
856 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
404 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
452 KB |
Output is correct |
35 |
Correct |
1 ms |
860 KB |
Output is correct |
36 |
Correct |
1 ms |
860 KB |
Output is correct |
37 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
860 KB |
Output is correct |
45 |
Correct |
1 ms |
860 KB |
Output is correct |
46 |
Correct |
3 ms |
2908 KB |
Output is correct |
47 |
Correct |
225 ms |
24740 KB |
Output is correct |
48 |
Correct |
203 ms |
16076 KB |
Output is correct |
49 |
Correct |
204 ms |
16204 KB |
Output is correct |
50 |
Correct |
192 ms |
24916 KB |
Output is correct |
51 |
Correct |
183 ms |
24728 KB |
Output is correct |
52 |
Correct |
217 ms |
24764 KB |
Output is correct |
53 |
Correct |
227 ms |
24912 KB |
Output is correct |
54 |
Correct |
12 ms |
14684 KB |
Output is correct |
55 |
Correct |
12 ms |
14684 KB |
Output is correct |
56 |
Correct |
12 ms |
14684 KB |
Output is correct |
57 |
Correct |
13 ms |
14684 KB |
Output is correct |
58 |
Correct |
13 ms |
14684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
56 ms |
3376 KB |
Output is correct |
3 |
Correct |
39 ms |
3172 KB |
Output is correct |
4 |
Correct |
32 ms |
2724 KB |
Output is correct |
5 |
Correct |
42 ms |
3152 KB |
Output is correct |
6 |
Correct |
31 ms |
2644 KB |
Output is correct |
7 |
Correct |
47 ms |
3604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 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 |
600 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 |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
158 ms |
8352 KB |
Output is correct |
21 |
Correct |
143 ms |
7548 KB |
Output is correct |
22 |
Correct |
141 ms |
7504 KB |
Output is correct |
23 |
Correct |
135 ms |
8792 KB |
Output is correct |
24 |
Correct |
126 ms |
8532 KB |
Output is correct |
25 |
Correct |
146 ms |
8484 KB |
Output is correct |
26 |
Correct |
159 ms |
8528 KB |
Output is correct |
27 |
Correct |
1 ms |
856 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
404 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
452 KB |
Output is correct |
35 |
Correct |
1 ms |
860 KB |
Output is correct |
36 |
Correct |
1 ms |
860 KB |
Output is correct |
37 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
860 KB |
Output is correct |
45 |
Correct |
1 ms |
860 KB |
Output is correct |
46 |
Correct |
3 ms |
2908 KB |
Output is correct |
47 |
Correct |
225 ms |
24740 KB |
Output is correct |
48 |
Correct |
203 ms |
16076 KB |
Output is correct |
49 |
Correct |
204 ms |
16204 KB |
Output is correct |
50 |
Correct |
192 ms |
24916 KB |
Output is correct |
51 |
Correct |
183 ms |
24728 KB |
Output is correct |
52 |
Correct |
217 ms |
24764 KB |
Output is correct |
53 |
Correct |
227 ms |
24912 KB |
Output is correct |
54 |
Correct |
12 ms |
14684 KB |
Output is correct |
55 |
Correct |
12 ms |
14684 KB |
Output is correct |
56 |
Correct |
12 ms |
14684 KB |
Output is correct |
57 |
Correct |
13 ms |
14684 KB |
Output is correct |
58 |
Correct |
13 ms |
14684 KB |
Output is correct |
59 |
Correct |
283 ms |
85840 KB |
Output is correct |
60 |
Correct |
246 ms |
171348 KB |
Output is correct |
61 |
Correct |
244 ms |
171472 KB |
Output is correct |
62 |
Correct |
270 ms |
171608 KB |
Output is correct |
63 |
Correct |
307 ms |
85572 KB |
Output is correct |
64 |
Correct |
397 ms |
178256 KB |
Output is correct |
65 |
Correct |
400 ms |
178200 KB |
Output is correct |
66 |
Correct |
351 ms |
178572 KB |
Output is correct |
67 |
Correct |
340 ms |
178260 KB |
Output is correct |
68 |
Correct |
377 ms |
178468 KB |
Output is correct |
69 |
Correct |
402 ms |
178532 KB |
Output is correct |
70 |
Correct |
133 ms |
166640 KB |
Output is correct |
71 |
Correct |
134 ms |
166504 KB |
Output is correct |
72 |
Correct |
134 ms |
166552 KB |
Output is correct |
73 |
Correct |
134 ms |
166488 KB |
Output is correct |
74 |
Correct |
136 ms |
166484 KB |
Output is correct |
75 |
Correct |
140 ms |
166736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
2908 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Runtime error |
594 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |