#include <bits/stdc++.h>
using namespace std;
#define ll long long
int a[300'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 |
4444 KB |
Output is correct |
2 |
Correct |
5 ms |
10712 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Runtime error |
778 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 |
Correct |
5 ms |
10712 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Runtime error |
778 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 |
Correct |
47 ms |
6124 KB |
Output is correct |
3 |
Correct |
50 ms |
6692 KB |
Output is correct |
4 |
Correct |
34 ms |
6564 KB |
Output is correct |
5 |
Correct |
43 ms |
6852 KB |
Output is correct |
6 |
Correct |
37 ms |
6480 KB |
Output is correct |
7 |
Correct |
47 ms |
6860 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
47 ms |
6124 KB |
Output is correct |
3 |
Correct |
50 ms |
6692 KB |
Output is correct |
4 |
Correct |
34 ms |
6564 KB |
Output is correct |
5 |
Correct |
43 ms |
6852 KB |
Output is correct |
6 |
Correct |
37 ms |
6480 KB |
Output is correct |
7 |
Correct |
47 ms |
6860 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
158 ms |
10044 KB |
Output is correct |
21 |
Correct |
168 ms |
9328 KB |
Output is correct |
22 |
Correct |
149 ms |
9324 KB |
Output is correct |
23 |
Correct |
134 ms |
10320 KB |
Output is correct |
24 |
Correct |
133 ms |
9960 KB |
Output is correct |
25 |
Correct |
156 ms |
10252 KB |
Output is correct |
26 |
Correct |
161 ms |
10068 KB |
Output is correct |
27 |
Correct |
1 ms |
5272 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4440 KB |
Output is correct |
33 |
Correct |
1 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
4952 KB |
Output is correct |
35 |
Correct |
1 ms |
5464 KB |
Output is correct |
36 |
Correct |
1 ms |
5468 KB |
Output is correct |
37 |
Correct |
1 ms |
4440 KB |
Output is correct |
38 |
Correct |
1 ms |
4440 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
4700 KB |
Output is correct |
43 |
Correct |
1 ms |
4952 KB |
Output is correct |
44 |
Correct |
1 ms |
5464 KB |
Output is correct |
45 |
Correct |
1 ms |
5468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
47 ms |
6124 KB |
Output is correct |
3 |
Correct |
50 ms |
6692 KB |
Output is correct |
4 |
Correct |
34 ms |
6564 KB |
Output is correct |
5 |
Correct |
43 ms |
6852 KB |
Output is correct |
6 |
Correct |
37 ms |
6480 KB |
Output is correct |
7 |
Correct |
47 ms |
6860 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
158 ms |
10044 KB |
Output is correct |
21 |
Correct |
168 ms |
9328 KB |
Output is correct |
22 |
Correct |
149 ms |
9324 KB |
Output is correct |
23 |
Correct |
134 ms |
10320 KB |
Output is correct |
24 |
Correct |
133 ms |
9960 KB |
Output is correct |
25 |
Correct |
156 ms |
10252 KB |
Output is correct |
26 |
Correct |
161 ms |
10068 KB |
Output is correct |
27 |
Correct |
1 ms |
5272 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4440 KB |
Output is correct |
33 |
Correct |
1 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
4952 KB |
Output is correct |
35 |
Correct |
1 ms |
5464 KB |
Output is correct |
36 |
Correct |
1 ms |
5468 KB |
Output is correct |
37 |
Correct |
1 ms |
4440 KB |
Output is correct |
38 |
Correct |
1 ms |
4440 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
4700 KB |
Output is correct |
43 |
Correct |
1 ms |
4952 KB |
Output is correct |
44 |
Correct |
1 ms |
5464 KB |
Output is correct |
45 |
Correct |
1 ms |
5468 KB |
Output is correct |
46 |
Correct |
5 ms |
10584 KB |
Output is correct |
47 |
Correct |
232 ms |
31384 KB |
Output is correct |
48 |
Correct |
205 ms |
21072 KB |
Output is correct |
49 |
Correct |
205 ms |
21132 KB |
Output is correct |
50 |
Correct |
189 ms |
29624 KB |
Output is correct |
51 |
Correct |
187 ms |
29344 KB |
Output is correct |
52 |
Correct |
230 ms |
31280 KB |
Output is correct |
53 |
Correct |
233 ms |
31560 KB |
Output is correct |
54 |
Correct |
13 ms |
23384 KB |
Output is correct |
55 |
Correct |
13 ms |
23376 KB |
Output is correct |
56 |
Correct |
13 ms |
25436 KB |
Output is correct |
57 |
Correct |
13 ms |
23548 KB |
Output is correct |
58 |
Correct |
13 ms |
25436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
47 ms |
6124 KB |
Output is correct |
3 |
Correct |
50 ms |
6692 KB |
Output is correct |
4 |
Correct |
34 ms |
6564 KB |
Output is correct |
5 |
Correct |
43 ms |
6852 KB |
Output is correct |
6 |
Correct |
37 ms |
6480 KB |
Output is correct |
7 |
Correct |
47 ms |
6860 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
158 ms |
10044 KB |
Output is correct |
21 |
Correct |
168 ms |
9328 KB |
Output is correct |
22 |
Correct |
149 ms |
9324 KB |
Output is correct |
23 |
Correct |
134 ms |
10320 KB |
Output is correct |
24 |
Correct |
133 ms |
9960 KB |
Output is correct |
25 |
Correct |
156 ms |
10252 KB |
Output is correct |
26 |
Correct |
161 ms |
10068 KB |
Output is correct |
27 |
Correct |
1 ms |
5272 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4440 KB |
Output is correct |
33 |
Correct |
1 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
4952 KB |
Output is correct |
35 |
Correct |
1 ms |
5464 KB |
Output is correct |
36 |
Correct |
1 ms |
5468 KB |
Output is correct |
37 |
Correct |
1 ms |
4440 KB |
Output is correct |
38 |
Correct |
1 ms |
4440 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
4700 KB |
Output is correct |
43 |
Correct |
1 ms |
4952 KB |
Output is correct |
44 |
Correct |
1 ms |
5464 KB |
Output is correct |
45 |
Correct |
1 ms |
5468 KB |
Output is correct |
46 |
Correct |
5 ms |
10584 KB |
Output is correct |
47 |
Correct |
232 ms |
31384 KB |
Output is correct |
48 |
Correct |
205 ms |
21072 KB |
Output is correct |
49 |
Correct |
205 ms |
21132 KB |
Output is correct |
50 |
Correct |
189 ms |
29624 KB |
Output is correct |
51 |
Correct |
187 ms |
29344 KB |
Output is correct |
52 |
Correct |
230 ms |
31280 KB |
Output is correct |
53 |
Correct |
233 ms |
31560 KB |
Output is correct |
54 |
Correct |
13 ms |
23384 KB |
Output is correct |
55 |
Correct |
13 ms |
23376 KB |
Output is correct |
56 |
Correct |
13 ms |
25436 KB |
Output is correct |
57 |
Correct |
13 ms |
23548 KB |
Output is correct |
58 |
Correct |
13 ms |
25436 KB |
Output is correct |
59 |
Correct |
290 ms |
103548 KB |
Output is correct |
60 |
Correct |
288 ms |
200660 KB |
Output is correct |
61 |
Correct |
259 ms |
201032 KB |
Output is correct |
62 |
Correct |
261 ms |
203080 KB |
Output is correct |
63 |
Correct |
304 ms |
103464 KB |
Output is correct |
64 |
Correct |
436 ms |
206960 KB |
Output is correct |
65 |
Correct |
402 ms |
206672 KB |
Output is correct |
66 |
Correct |
371 ms |
195072 KB |
Output is correct |
67 |
Correct |
337 ms |
194544 KB |
Output is correct |
68 |
Correct |
409 ms |
206744 KB |
Output is correct |
69 |
Correct |
437 ms |
207008 KB |
Output is correct |
70 |
Correct |
128 ms |
189776 KB |
Output is correct |
71 |
Correct |
130 ms |
191792 KB |
Output is correct |
72 |
Correct |
130 ms |
198028 KB |
Output is correct |
73 |
Correct |
130 ms |
193968 KB |
Output is correct |
74 |
Correct |
137 ms |
200016 KB |
Output is correct |
75 |
Correct |
136 ms |
200272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
5 ms |
10712 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Runtime error |
778 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |