#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);
int n,m;
cin>>n>>m;
int a[n][m];
map <int,int> mp;
vector <int> v;
for(int i=0;i<n;i++){
int x=0;
for(int j=0;j<m;j++){
cin>>a[i][j];
if(a[i][j]==1)x+=(1<<j);
}
v.pb(x);
mp[x]++;
}
vector <int> cnt,cnt2((1<<m));
for(int i=0;i<m;i++){
int kol=0;
for(int j=0;j<n;j++){
if(a[j][i]==1)kol++;
}
cnt.pb(kol);
}
for(int i=0;i<(1<<m);i++){
for(int j=0;j<m;j++){
if((i & (1<<j))!=0)cnt2[i]++;
}
}
if(n<=3000){
for(int i=0;i<n;i++){
for(int k=0;k<m;k++){
if(a[i][k]==1)cnt[k]--;
}
int mx=0;
for(int j=0;j<n;j++){
if(i!=j){
int kol=0;
for(int k=0;k<m;k++){
if(a[j][k]==1)cnt[k]--;
}
for(int k=0;k<m;k++){
if(cnt[k]>=n/2)kol++;
}
for(int k=0;k<m;k++){
if(a[j][k]==1)cnt[k]++;
}
mx=max(mx,kol);
}
}
cout<<mx<<"\n";
for(int k=0;k<m;k++){
if(a[i][k]==1)cnt[k]++;
}
}
return 0;
}
for(int i=0;i<n;i++){
int mx=0,kol=0,min=0;
mp[v[i]]--;
for(int j=0;j<m;j++){
if(a[i][j]==1)cnt[j]--;
if(cnt[j]>=n/2)kol++;
if(cnt[j]==n/2)min+=(1<<j);
}
for(int j=0;j<(1<<m);j++){
int x=j&min;
if(mp[j]!=0)mx=max(mx,kol-cnt2[x]);
}
mp[v[i]]++;
for(int j=0;j<m;j++){
if(a[i][j]==1)cnt[j]++;
}
cout<<mx<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
48 ms |
8540 KB |
Output is correct |
6 |
Correct |
52 ms |
8684 KB |
Output is correct |
7 |
Correct |
49 ms |
8536 KB |
Output is correct |
8 |
Correct |
49 ms |
8540 KB |
Output is correct |
9 |
Correct |
64 ms |
8540 KB |
Output is correct |
10 |
Correct |
48 ms |
8540 KB |
Output is correct |
11 |
Correct |
48 ms |
8536 KB |
Output is correct |
12 |
Correct |
65 ms |
8540 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 |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
356 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
4 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 |
600 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
484 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
576 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
6 ms |
1460 KB |
Output is correct |
47 |
Correct |
6 ms |
1472 KB |
Output is correct |
48 |
Correct |
6 ms |
1372 KB |
Output is correct |
49 |
Correct |
6 ms |
1372 KB |
Output is correct |
50 |
Correct |
6 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
48 ms |
8540 KB |
Output is correct |
6 |
Correct |
52 ms |
8684 KB |
Output is correct |
7 |
Correct |
49 ms |
8536 KB |
Output is correct |
8 |
Correct |
49 ms |
8540 KB |
Output is correct |
9 |
Correct |
64 ms |
8540 KB |
Output is correct |
10 |
Correct |
48 ms |
8540 KB |
Output is correct |
11 |
Correct |
48 ms |
8536 KB |
Output is correct |
12 |
Correct |
65 ms |
8540 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 |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
356 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
4 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 |
600 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
484 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
576 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
6 ms |
1460 KB |
Output is correct |
47 |
Correct |
6 ms |
1472 KB |
Output is correct |
48 |
Correct |
6 ms |
1372 KB |
Output is correct |
49 |
Correct |
6 ms |
1372 KB |
Output is correct |
50 |
Correct |
6 ms |
1372 KB |
Output is correct |
51 |
Correct |
372 ms |
9172 KB |
Output is correct |
52 |
Correct |
498 ms |
9048 KB |
Output is correct |
53 |
Correct |
1972 ms |
9328 KB |
Output is correct |
54 |
Correct |
1975 ms |
9568 KB |
Output is correct |
55 |
Correct |
72 ms |
516 KB |
Output is correct |
56 |
Correct |
1681 ms |
2068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
89 ms |
9412 KB |
Output is correct |
3 |
Correct |
93 ms |
10024 KB |
Output is correct |
4 |
Correct |
60 ms |
7456 KB |
Output is correct |
5 |
Correct |
105 ms |
10828 KB |
Output is correct |
6 |
Correct |
62 ms |
7332 KB |
Output is correct |
7 |
Correct |
99 ms |
9428 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
75 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
89 ms |
9412 KB |
Output is correct |
3 |
Correct |
93 ms |
10024 KB |
Output is correct |
4 |
Correct |
60 ms |
7456 KB |
Output is correct |
5 |
Correct |
105 ms |
10828 KB |
Output is correct |
6 |
Correct |
62 ms |
7332 KB |
Output is correct |
7 |
Correct |
99 ms |
9428 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
75 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
352 KB |
Output is correct |
20 |
Execution timed out |
4078 ms |
28556 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
89 ms |
9412 KB |
Output is correct |
3 |
Correct |
93 ms |
10024 KB |
Output is correct |
4 |
Correct |
60 ms |
7456 KB |
Output is correct |
5 |
Correct |
105 ms |
10828 KB |
Output is correct |
6 |
Correct |
62 ms |
7332 KB |
Output is correct |
7 |
Correct |
99 ms |
9428 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
75 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
352 KB |
Output is correct |
20 |
Execution timed out |
4078 ms |
28556 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
89 ms |
9412 KB |
Output is correct |
3 |
Correct |
93 ms |
10024 KB |
Output is correct |
4 |
Correct |
60 ms |
7456 KB |
Output is correct |
5 |
Correct |
105 ms |
10828 KB |
Output is correct |
6 |
Correct |
62 ms |
7332 KB |
Output is correct |
7 |
Correct |
99 ms |
9428 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
75 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
352 KB |
Output is correct |
20 |
Execution timed out |
4078 ms |
28556 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
48 ms |
8540 KB |
Output is correct |
6 |
Correct |
52 ms |
8684 KB |
Output is correct |
7 |
Correct |
49 ms |
8536 KB |
Output is correct |
8 |
Correct |
49 ms |
8540 KB |
Output is correct |
9 |
Correct |
64 ms |
8540 KB |
Output is correct |
10 |
Correct |
48 ms |
8540 KB |
Output is correct |
11 |
Correct |
48 ms |
8536 KB |
Output is correct |
12 |
Correct |
65 ms |
8540 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 |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
356 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
4 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 |
600 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
484 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
576 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
6 ms |
1460 KB |
Output is correct |
47 |
Correct |
6 ms |
1472 KB |
Output is correct |
48 |
Correct |
6 ms |
1372 KB |
Output is correct |
49 |
Correct |
6 ms |
1372 KB |
Output is correct |
50 |
Correct |
6 ms |
1372 KB |
Output is correct |
51 |
Correct |
372 ms |
9172 KB |
Output is correct |
52 |
Correct |
498 ms |
9048 KB |
Output is correct |
53 |
Correct |
1972 ms |
9328 KB |
Output is correct |
54 |
Correct |
1975 ms |
9568 KB |
Output is correct |
55 |
Correct |
72 ms |
516 KB |
Output is correct |
56 |
Correct |
1681 ms |
2068 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
89 ms |
9412 KB |
Output is correct |
59 |
Correct |
93 ms |
10024 KB |
Output is correct |
60 |
Correct |
60 ms |
7456 KB |
Output is correct |
61 |
Correct |
105 ms |
10828 KB |
Output is correct |
62 |
Correct |
62 ms |
7332 KB |
Output is correct |
63 |
Correct |
99 ms |
9428 KB |
Output is correct |
64 |
Correct |
1 ms |
344 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
0 ms |
348 KB |
Output is correct |
68 |
Correct |
1 ms |
348 KB |
Output is correct |
69 |
Correct |
0 ms |
348 KB |
Output is correct |
70 |
Correct |
1 ms |
348 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
75 ms |
348 KB |
Output is correct |
74 |
Correct |
1 ms |
348 KB |
Output is correct |
75 |
Correct |
0 ms |
352 KB |
Output is correct |
76 |
Execution timed out |
4078 ms |
28556 KB |
Time limit exceeded |
77 |
Halted |
0 ms |
0 KB |
- |