#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 300000;
const int M = 20;
int n, m;
int a[N];
int pr[(1 << M)][5];
vector<int> v[(1 << M)];
void add(int i) {
int x = (((1 << m) - 1) ^ a[i]);
if((int)v[x].size() == 2) return;
for(int msk = x; msk > 0; msk = ((msk - 1) & x)) {
if(v[msk].size() == 2) continue;
if(v[msk].empty() || v[msk].back() != i)
v[msk].push_back(i);
}
}
int func(int msk, int i) {
return __builtin_popcount((msk & a[i]));
}
int T = (1 << 0) + (1 << 3) + (1 << 6) + (1 << 7) + (1 << 8) + (1 << 10);
void add1(int msk, int i) {
// if(msk == T) cout << i << ' ' << func(msk, i) << '\n';
if(pr[msk][0] == i || pr[msk][1] == i) return;
pr[msk][2] = i;
if(func(msk, pr[msk][2]) < func(msk, pr[msk][1]))
swap(pr[msk][1], pr[msk][2]);
if(func(msk, pr[msk][1]) < func(msk, pr[msk][0]))
swap(pr[msk][0], pr[msk][1]);
if(func(msk, pr[msk][2]) < func(msk, pr[msk][1]))
swap(pr[msk][1], pr[msk][2]);
}
void print(int x) {
for(int j = 0; j < m; j++)
cout << ((x >> j) & 1);
cout << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> m;
vector<int> cnt(m);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
bool bt;
cin >> bt;
if(bt) {
a[i] |= (1 << j);
cnt[j]++;
}
}
add(i);
}
for(int msk = 0; msk < (1 << m); msk++) {
pr[msk][0] = 0; pr[msk][1] = 1;
for(int x = msk; x > 0; x = ((x - 1) & msk)) {
for(int c : v[x]) {
add1(msk, c);
}
}
}
for(int i = 0; i < n; i++) {
int msk = 0, ans = 0;
for(int j = 0; j < m; j++) {
int x = cnt[j] - (a[i] >> j & 1);
if(x >= n / 2) ans++;
if(x == n / 2)
msk |= (1 << j);
}
int k = pr[msk][(pr[msk][0] == i)];
ans -= func(msk, k);
cout << ans << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
24916 KB |
Output is correct |
2 |
Correct |
14 ms |
25044 KB |
Output is correct |
3 |
Correct |
13 ms |
24916 KB |
Output is correct |
4 |
Correct |
12 ms |
24916 KB |
Output is correct |
5 |
Execution timed out |
4046 ms |
46152 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
24916 KB |
Output is correct |
2 |
Correct |
14 ms |
25044 KB |
Output is correct |
3 |
Correct |
13 ms |
24916 KB |
Output is correct |
4 |
Correct |
12 ms |
24916 KB |
Output is correct |
5 |
Execution timed out |
4046 ms |
46152 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
24916 KB |
Output is correct |
2 |
Correct |
59 ms |
26588 KB |
Output is correct |
3 |
Correct |
54 ms |
25456 KB |
Output is correct |
4 |
Correct |
45 ms |
26704 KB |
Output is correct |
5 |
Correct |
65 ms |
26604 KB |
Output is correct |
6 |
Correct |
45 ms |
26652 KB |
Output is correct |
7 |
Correct |
63 ms |
27084 KB |
Output is correct |
8 |
Correct |
13 ms |
24840 KB |
Output is correct |
9 |
Correct |
13 ms |
24944 KB |
Output is correct |
10 |
Correct |
13 ms |
24960 KB |
Output is correct |
11 |
Correct |
14 ms |
24956 KB |
Output is correct |
12 |
Correct |
15 ms |
24952 KB |
Output is correct |
13 |
Correct |
13 ms |
24944 KB |
Output is correct |
14 |
Correct |
15 ms |
24840 KB |
Output is correct |
15 |
Correct |
14 ms |
24916 KB |
Output is correct |
16 |
Correct |
15 ms |
24964 KB |
Output is correct |
17 |
Correct |
14 ms |
24916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
24916 KB |
Output is correct |
2 |
Correct |
59 ms |
26588 KB |
Output is correct |
3 |
Correct |
54 ms |
25456 KB |
Output is correct |
4 |
Correct |
45 ms |
26704 KB |
Output is correct |
5 |
Correct |
65 ms |
26604 KB |
Output is correct |
6 |
Correct |
45 ms |
26652 KB |
Output is correct |
7 |
Correct |
63 ms |
27084 KB |
Output is correct |
8 |
Correct |
13 ms |
24840 KB |
Output is correct |
9 |
Correct |
13 ms |
24944 KB |
Output is correct |
10 |
Correct |
13 ms |
24960 KB |
Output is correct |
11 |
Correct |
14 ms |
24956 KB |
Output is correct |
12 |
Correct |
15 ms |
24952 KB |
Output is correct |
13 |
Correct |
13 ms |
24944 KB |
Output is correct |
14 |
Correct |
15 ms |
24840 KB |
Output is correct |
15 |
Correct |
14 ms |
24916 KB |
Output is correct |
16 |
Correct |
15 ms |
24964 KB |
Output is correct |
17 |
Correct |
14 ms |
24916 KB |
Output is correct |
18 |
Correct |
12 ms |
24916 KB |
Output is correct |
19 |
Correct |
13 ms |
24948 KB |
Output is correct |
20 |
Correct |
192 ms |
27100 KB |
Output is correct |
21 |
Correct |
186 ms |
27068 KB |
Output is correct |
22 |
Correct |
179 ms |
27080 KB |
Output is correct |
23 |
Correct |
177 ms |
27352 KB |
Output is correct |
24 |
Correct |
161 ms |
25976 KB |
Output is correct |
25 |
Correct |
187 ms |
27132 KB |
Output is correct |
26 |
Correct |
197 ms |
27048 KB |
Output is correct |
27 |
Correct |
13 ms |
24916 KB |
Output is correct |
28 |
Correct |
14 ms |
24848 KB |
Output is correct |
29 |
Correct |
13 ms |
24844 KB |
Output is correct |
30 |
Correct |
13 ms |
24876 KB |
Output is correct |
31 |
Correct |
16 ms |
24976 KB |
Output is correct |
32 |
Correct |
13 ms |
24956 KB |
Output is correct |
33 |
Correct |
14 ms |
24884 KB |
Output is correct |
34 |
Correct |
13 ms |
24916 KB |
Output is correct |
35 |
Correct |
14 ms |
24916 KB |
Output is correct |
36 |
Correct |
15 ms |
24916 KB |
Output is correct |
37 |
Correct |
13 ms |
24948 KB |
Output is correct |
38 |
Correct |
13 ms |
24916 KB |
Output is correct |
39 |
Correct |
12 ms |
24924 KB |
Output is correct |
40 |
Correct |
13 ms |
24864 KB |
Output is correct |
41 |
Correct |
14 ms |
24864 KB |
Output is correct |
42 |
Correct |
13 ms |
24920 KB |
Output is correct |
43 |
Correct |
13 ms |
24916 KB |
Output is correct |
44 |
Correct |
15 ms |
24976 KB |
Output is correct |
45 |
Correct |
15 ms |
24952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
24916 KB |
Output is correct |
2 |
Correct |
59 ms |
26588 KB |
Output is correct |
3 |
Correct |
54 ms |
25456 KB |
Output is correct |
4 |
Correct |
45 ms |
26704 KB |
Output is correct |
5 |
Correct |
65 ms |
26604 KB |
Output is correct |
6 |
Correct |
45 ms |
26652 KB |
Output is correct |
7 |
Correct |
63 ms |
27084 KB |
Output is correct |
8 |
Correct |
13 ms |
24840 KB |
Output is correct |
9 |
Correct |
13 ms |
24944 KB |
Output is correct |
10 |
Correct |
13 ms |
24960 KB |
Output is correct |
11 |
Correct |
14 ms |
24956 KB |
Output is correct |
12 |
Correct |
15 ms |
24952 KB |
Output is correct |
13 |
Correct |
13 ms |
24944 KB |
Output is correct |
14 |
Correct |
15 ms |
24840 KB |
Output is correct |
15 |
Correct |
14 ms |
24916 KB |
Output is correct |
16 |
Correct |
15 ms |
24964 KB |
Output is correct |
17 |
Correct |
14 ms |
24916 KB |
Output is correct |
18 |
Correct |
12 ms |
24916 KB |
Output is correct |
19 |
Correct |
13 ms |
24948 KB |
Output is correct |
20 |
Correct |
192 ms |
27100 KB |
Output is correct |
21 |
Correct |
186 ms |
27068 KB |
Output is correct |
22 |
Correct |
179 ms |
27080 KB |
Output is correct |
23 |
Correct |
177 ms |
27352 KB |
Output is correct |
24 |
Correct |
161 ms |
25976 KB |
Output is correct |
25 |
Correct |
187 ms |
27132 KB |
Output is correct |
26 |
Correct |
197 ms |
27048 KB |
Output is correct |
27 |
Correct |
13 ms |
24916 KB |
Output is correct |
28 |
Correct |
14 ms |
24848 KB |
Output is correct |
29 |
Correct |
13 ms |
24844 KB |
Output is correct |
30 |
Correct |
13 ms |
24876 KB |
Output is correct |
31 |
Correct |
16 ms |
24976 KB |
Output is correct |
32 |
Correct |
13 ms |
24956 KB |
Output is correct |
33 |
Correct |
14 ms |
24884 KB |
Output is correct |
34 |
Correct |
13 ms |
24916 KB |
Output is correct |
35 |
Correct |
14 ms |
24916 KB |
Output is correct |
36 |
Correct |
15 ms |
24916 KB |
Output is correct |
37 |
Correct |
13 ms |
24948 KB |
Output is correct |
38 |
Correct |
13 ms |
24916 KB |
Output is correct |
39 |
Correct |
12 ms |
24924 KB |
Output is correct |
40 |
Correct |
13 ms |
24864 KB |
Output is correct |
41 |
Correct |
14 ms |
24864 KB |
Output is correct |
42 |
Correct |
13 ms |
24920 KB |
Output is correct |
43 |
Correct |
13 ms |
24916 KB |
Output is correct |
44 |
Correct |
15 ms |
24976 KB |
Output is correct |
45 |
Correct |
15 ms |
24952 KB |
Output is correct |
46 |
Correct |
14 ms |
25044 KB |
Output is correct |
47 |
Correct |
374 ms |
27864 KB |
Output is correct |
48 |
Correct |
276 ms |
27300 KB |
Output is correct |
49 |
Correct |
278 ms |
27420 KB |
Output is correct |
50 |
Correct |
243 ms |
27524 KB |
Output is correct |
51 |
Correct |
245 ms |
26608 KB |
Output is correct |
52 |
Correct |
346 ms |
27804 KB |
Output is correct |
53 |
Correct |
358 ms |
27984 KB |
Output is correct |
54 |
Correct |
59 ms |
25408 KB |
Output is correct |
55 |
Correct |
27 ms |
25236 KB |
Output is correct |
56 |
Correct |
72 ms |
25364 KB |
Output is correct |
57 |
Correct |
35 ms |
25292 KB |
Output is correct |
58 |
Correct |
59 ms |
25316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
24916 KB |
Output is correct |
2 |
Correct |
59 ms |
26588 KB |
Output is correct |
3 |
Correct |
54 ms |
25456 KB |
Output is correct |
4 |
Correct |
45 ms |
26704 KB |
Output is correct |
5 |
Correct |
65 ms |
26604 KB |
Output is correct |
6 |
Correct |
45 ms |
26652 KB |
Output is correct |
7 |
Correct |
63 ms |
27084 KB |
Output is correct |
8 |
Correct |
13 ms |
24840 KB |
Output is correct |
9 |
Correct |
13 ms |
24944 KB |
Output is correct |
10 |
Correct |
13 ms |
24960 KB |
Output is correct |
11 |
Correct |
14 ms |
24956 KB |
Output is correct |
12 |
Correct |
15 ms |
24952 KB |
Output is correct |
13 |
Correct |
13 ms |
24944 KB |
Output is correct |
14 |
Correct |
15 ms |
24840 KB |
Output is correct |
15 |
Correct |
14 ms |
24916 KB |
Output is correct |
16 |
Correct |
15 ms |
24964 KB |
Output is correct |
17 |
Correct |
14 ms |
24916 KB |
Output is correct |
18 |
Correct |
12 ms |
24916 KB |
Output is correct |
19 |
Correct |
13 ms |
24948 KB |
Output is correct |
20 |
Correct |
192 ms |
27100 KB |
Output is correct |
21 |
Correct |
186 ms |
27068 KB |
Output is correct |
22 |
Correct |
179 ms |
27080 KB |
Output is correct |
23 |
Correct |
177 ms |
27352 KB |
Output is correct |
24 |
Correct |
161 ms |
25976 KB |
Output is correct |
25 |
Correct |
187 ms |
27132 KB |
Output is correct |
26 |
Correct |
197 ms |
27048 KB |
Output is correct |
27 |
Correct |
13 ms |
24916 KB |
Output is correct |
28 |
Correct |
14 ms |
24848 KB |
Output is correct |
29 |
Correct |
13 ms |
24844 KB |
Output is correct |
30 |
Correct |
13 ms |
24876 KB |
Output is correct |
31 |
Correct |
16 ms |
24976 KB |
Output is correct |
32 |
Correct |
13 ms |
24956 KB |
Output is correct |
33 |
Correct |
14 ms |
24884 KB |
Output is correct |
34 |
Correct |
13 ms |
24916 KB |
Output is correct |
35 |
Correct |
14 ms |
24916 KB |
Output is correct |
36 |
Correct |
15 ms |
24916 KB |
Output is correct |
37 |
Correct |
13 ms |
24948 KB |
Output is correct |
38 |
Correct |
13 ms |
24916 KB |
Output is correct |
39 |
Correct |
12 ms |
24924 KB |
Output is correct |
40 |
Correct |
13 ms |
24864 KB |
Output is correct |
41 |
Correct |
14 ms |
24864 KB |
Output is correct |
42 |
Correct |
13 ms |
24920 KB |
Output is correct |
43 |
Correct |
13 ms |
24916 KB |
Output is correct |
44 |
Correct |
15 ms |
24976 KB |
Output is correct |
45 |
Correct |
15 ms |
24952 KB |
Output is correct |
46 |
Correct |
14 ms |
25044 KB |
Output is correct |
47 |
Correct |
374 ms |
27864 KB |
Output is correct |
48 |
Correct |
276 ms |
27300 KB |
Output is correct |
49 |
Correct |
278 ms |
27420 KB |
Output is correct |
50 |
Correct |
243 ms |
27524 KB |
Output is correct |
51 |
Correct |
245 ms |
26608 KB |
Output is correct |
52 |
Correct |
346 ms |
27804 KB |
Output is correct |
53 |
Correct |
358 ms |
27984 KB |
Output is correct |
54 |
Correct |
59 ms |
25408 KB |
Output is correct |
55 |
Correct |
27 ms |
25236 KB |
Output is correct |
56 |
Correct |
72 ms |
25364 KB |
Output is correct |
57 |
Correct |
35 ms |
25292 KB |
Output is correct |
58 |
Correct |
59 ms |
25316 KB |
Output is correct |
59 |
Correct |
1396 ms |
31176 KB |
Output is correct |
60 |
Correct |
3220 ms |
33760 KB |
Output is correct |
61 |
Correct |
3298 ms |
33964 KB |
Output is correct |
62 |
Correct |
3321 ms |
34120 KB |
Output is correct |
63 |
Correct |
1405 ms |
31684 KB |
Output is correct |
64 |
Correct |
3878 ms |
33992 KB |
Output is correct |
65 |
Correct |
3943 ms |
34220 KB |
Output is correct |
66 |
Correct |
468 ms |
31164 KB |
Output is correct |
67 |
Correct |
1381 ms |
33872 KB |
Output is correct |
68 |
Correct |
3792 ms |
34992 KB |
Output is correct |
69 |
Correct |
3794 ms |
35276 KB |
Output is correct |
70 |
Correct |
1424 ms |
29524 KB |
Output is correct |
71 |
Correct |
336 ms |
27504 KB |
Output is correct |
72 |
Correct |
856 ms |
27824 KB |
Output is correct |
73 |
Correct |
367 ms |
27724 KB |
Output is correct |
74 |
Correct |
1099 ms |
28260 KB |
Output is correct |
75 |
Correct |
3202 ms |
31392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
24916 KB |
Output is correct |
2 |
Correct |
14 ms |
25044 KB |
Output is correct |
3 |
Correct |
13 ms |
24916 KB |
Output is correct |
4 |
Correct |
12 ms |
24916 KB |
Output is correct |
5 |
Execution timed out |
4046 ms |
46152 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |