#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 12, MOD = (int)1e9 + 7;
int n, m, c[N], a[N][20], s[N], f[N][2], who[N][2];
void u(int mask, int val = -1, int from = -1) {
if(val == -1) {
val = __builtin_popcount(mask);
}
if(from == who[mask][0]) {
f[mask][0] = max(f[mask][0], val);
return;
}
if(f[mask][0] < val) {
f[mask][1] = f[mask][0];
who[mask][1] = who[mask][0];
f[mask][0] = val;
who[mask][0] = from;
} else {
if(val > f[mask][1]) {
f[mask][1] = val;
who[mask][1] = from;
}
}
}
void test() {
cin >> n >> m;
for(int i = 1; i <= n; i++) {
for(int j = 0; j < m; j++) {
cin >> a[i][j];
if(a[i][j]) {
c[j]++;
} else {
s[i] += (1 << j);
}
}
u(s[i], -1, i);
}
for(int i = 0; i < m; i++) {
for(int j = 0; j < (1 << m); j++) {
if(!((j >> i) & 1)) {
int k = (j ^ (1 << i));
if(f[k][0]) {
u(j, -1, who[k][0]);
}
if(f[k][1]) {
u(j, -1, who[k][1]);
}
}
}
}
for(int i = 0; i < m; i++) {
for(int j = 0; j < (1 << m); j++) {
if(((j >> i) & 1)) {
int k = (j ^ (1 << i));
u(j, f[k][0], who[k][0]);
u(j, f[k][1], who[k][1]);
}
}
}
int val = n / 2;
for(int i = 1; i <= n; i++) {
int t = 0, cnt = 0;
for(int j = 0; j < m; j++) {
int k = c[j] - a[i][j];
if(k == val) {
t += (1 << j);
} else if(k > val) {
cnt++;
}
}
// int mx = 0;
// for(int j = 1; j <= n; j++) {
// if(j == i) continue;
// mx = max(mx, __builtin_popcount(s[j] & t));
// }
int ff = f[t][0];
if(who[t][0] == i) {
ff = f[t][1];
}
cout << ff + cnt << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
85 ms |
9836 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
85 ms |
9836 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
40 ms |
25644 KB |
Output is correct |
3 |
Correct |
43 ms |
26852 KB |
Output is correct |
4 |
Correct |
33 ms |
26204 KB |
Output is correct |
5 |
Correct |
45 ms |
26704 KB |
Output is correct |
6 |
Correct |
35 ms |
26204 KB |
Output is correct |
7 |
Correct |
47 ms |
26712 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 |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
516 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 |
732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
40 ms |
25644 KB |
Output is correct |
3 |
Correct |
43 ms |
26852 KB |
Output is correct |
4 |
Correct |
33 ms |
26204 KB |
Output is correct |
5 |
Correct |
45 ms |
26704 KB |
Output is correct |
6 |
Correct |
35 ms |
26204 KB |
Output is correct |
7 |
Correct |
47 ms |
26712 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 |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
516 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 |
732 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
140 ms |
31476 KB |
Output is correct |
21 |
Correct |
137 ms |
30844 KB |
Output is correct |
22 |
Correct |
129 ms |
30804 KB |
Output is correct |
23 |
Correct |
117 ms |
30544 KB |
Output is correct |
24 |
Correct |
126 ms |
31512 KB |
Output is correct |
25 |
Correct |
135 ms |
31576 KB |
Output is correct |
26 |
Correct |
148 ms |
31572 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 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 |
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 |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
1 ms |
344 KB |
Output is correct |
45 |
Correct |
1 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
40 ms |
25644 KB |
Output is correct |
3 |
Correct |
43 ms |
26852 KB |
Output is correct |
4 |
Correct |
33 ms |
26204 KB |
Output is correct |
5 |
Correct |
45 ms |
26704 KB |
Output is correct |
6 |
Correct |
35 ms |
26204 KB |
Output is correct |
7 |
Correct |
47 ms |
26712 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 |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
516 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 |
732 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
140 ms |
31476 KB |
Output is correct |
21 |
Correct |
137 ms |
30844 KB |
Output is correct |
22 |
Correct |
129 ms |
30804 KB |
Output is correct |
23 |
Correct |
117 ms |
30544 KB |
Output is correct |
24 |
Correct |
126 ms |
31512 KB |
Output is correct |
25 |
Correct |
135 ms |
31576 KB |
Output is correct |
26 |
Correct |
148 ms |
31572 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 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 |
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 |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
1 ms |
344 KB |
Output is correct |
45 |
Correct |
1 ms |
472 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
208 ms |
34128 KB |
Output is correct |
48 |
Correct |
191 ms |
33264 KB |
Output is correct |
49 |
Correct |
194 ms |
33300 KB |
Output is correct |
50 |
Correct |
161 ms |
33140 KB |
Output is correct |
51 |
Correct |
151 ms |
33980 KB |
Output is correct |
52 |
Correct |
199 ms |
34128 KB |
Output is correct |
53 |
Correct |
235 ms |
34384 KB |
Output is correct |
54 |
Correct |
2 ms |
604 KB |
Output is correct |
55 |
Correct |
1 ms |
604 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
692 KB |
Output is correct |
58 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
40 ms |
25644 KB |
Output is correct |
3 |
Correct |
43 ms |
26852 KB |
Output is correct |
4 |
Correct |
33 ms |
26204 KB |
Output is correct |
5 |
Correct |
45 ms |
26704 KB |
Output is correct |
6 |
Correct |
35 ms |
26204 KB |
Output is correct |
7 |
Correct |
47 ms |
26712 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 |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
516 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 |
732 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
140 ms |
31476 KB |
Output is correct |
21 |
Correct |
137 ms |
30844 KB |
Output is correct |
22 |
Correct |
129 ms |
30804 KB |
Output is correct |
23 |
Correct |
117 ms |
30544 KB |
Output is correct |
24 |
Correct |
126 ms |
31512 KB |
Output is correct |
25 |
Correct |
135 ms |
31576 KB |
Output is correct |
26 |
Correct |
148 ms |
31572 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 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 |
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 |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
1 ms |
344 KB |
Output is correct |
45 |
Correct |
1 ms |
472 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
208 ms |
34128 KB |
Output is correct |
48 |
Correct |
191 ms |
33264 KB |
Output is correct |
49 |
Correct |
194 ms |
33300 KB |
Output is correct |
50 |
Correct |
161 ms |
33140 KB |
Output is correct |
51 |
Correct |
151 ms |
33980 KB |
Output is correct |
52 |
Correct |
199 ms |
34128 KB |
Output is correct |
53 |
Correct |
235 ms |
34384 KB |
Output is correct |
54 |
Correct |
2 ms |
604 KB |
Output is correct |
55 |
Correct |
1 ms |
604 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
692 KB |
Output is correct |
58 |
Correct |
1 ms |
604 KB |
Output is correct |
59 |
Correct |
250 ms |
36432 KB |
Output is correct |
60 |
Correct |
124 ms |
16220 KB |
Output is correct |
61 |
Correct |
133 ms |
17092 KB |
Output is correct |
62 |
Correct |
124 ms |
17744 KB |
Output is correct |
63 |
Correct |
225 ms |
36016 KB |
Output is correct |
64 |
Correct |
309 ms |
37716 KB |
Output is correct |
65 |
Correct |
248 ms |
37712 KB |
Output is correct |
66 |
Correct |
188 ms |
35852 KB |
Output is correct |
67 |
Correct |
186 ms |
37712 KB |
Output is correct |
68 |
Correct |
238 ms |
37716 KB |
Output is correct |
69 |
Correct |
272 ms |
37972 KB |
Output is correct |
70 |
Correct |
10 ms |
2392 KB |
Output is correct |
71 |
Correct |
10 ms |
2396 KB |
Output is correct |
72 |
Correct |
10 ms |
2396 KB |
Output is correct |
73 |
Correct |
13 ms |
2456 KB |
Output is correct |
74 |
Correct |
10 ms |
2392 KB |
Output is correct |
75 |
Correct |
22 ms |
2892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
85 ms |
9836 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |