#include <bits/stdc++.h>
using namespace std;
const int N = 300001;
const int M = 20;
int a[N];
int sum[M], ans[N], mn[N], masks[N];
int dp[1<<10][1<<10], ppcnt[1<<10][1<<10];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for(int i=0; i< n; i++){
for(int j=0; j< m; j++){
int x;
cin >> x;
a[i]+=x<<j;
sum[j]+=x;
}
}
for(int i=0; i< n; i++)mn[i]=1e9;
for(int i=0; i< n; i++){
for(int j=0; j< m; j++)sum[j]-=(a[i] & (1<<j))>>j;
for(int j=0; j< m; j++){
if(sum[j]>=n/2)ans[i]++;
if(sum[j]==n/2)masks[i]+=1<<j;
}
for(int j=0; j< m; j++)sum[j]+=(a[i] & (1<<j))>>j;
}
for(int i=0; i< (1<<M); i++){
int f = i>>10;
int s = i%1024;
dp[f][s]=1e9;
ppcnt[f][s]=__builtin_popcount(f & s);
}
for(int i=0; i< n-1; i++){
int x = a[i];
int f = x>>10;
int s = x%1024;
if(m>10){
for(int j = 0; j<(1<<(m-10)); j++){
dp[j][s]= min(dp[j][s], ppcnt[j][f]);
}
}
x = masks[i+1];
f = x>>10;
s = x%1024;
for(int j=0; j<(1<<min(10, m)); j++){
mn[i+1]=min(mn[i+1], dp[f][j]+ppcnt[s][j]);
}
}
for(int i=0; i< (1<<M); i++){
int f = i>>10;
int s = i%1024;
dp[f][s]=1e9;
}
for(int i=n-1; i>0; i--){
int x = a[i];
int f = x>>10;
int s = x%1024;
if(m>10){
for(int j = 0; j<(1<<(m-10)); j++){
dp[j][s]= min(dp[j][s], ppcnt[j][f]);
}
}
x = masks[i-1];
f = x>>10;
s = x%1024;
for(int j=0; j<(1<<min(10, m)); j++){
mn[i-1]=min(mn[i-1], dp[f][j]+ppcnt[s][j]);
}
}
for(int i=0; i< n; i++){
cout << ans[i]-mn[i] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |