This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=3e5+5,M=2e6;
int a[N],dp1[M],f[20],n,m;
pair<int,int> dp2[M];
pair<int,int> merge(pair<int,int> x,pair<int,int> y){
vector<int> v;
v.pb(x.F);v.pb(x.S);v.pb(y.F);v.pb(y.S);
sort(v.begin(),v.end());
return {v[0],v[1]};
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
for (int i=0;i<M;i++) dp2[i]={INT_MAX,INT_MAX};
cin>>n>>m;
for (int i=1;i<=n;i++){
for (int j=0;j<m;j++){
bool x;cin>>x;
if (x) a[i]|=(1<<j),f[j]++;
}
dp1[a[i]]++;
dp2[a[i]]=merge({__builtin_popcount(a[i]),INT_MAX},dp2[a[i]]);
}
//for (int i=0;i<4;i++) cout<<dp2[i].F<<' '<<dp2[i].S<<" ";cout<<endl;
for (int j=0;j<m;j++){
for (int i=0;i<M;i++){
if (i&(1<<j)) dp1[i]+=dp1[i-(1<<j)];
else dp2[i]=merge(dp2[i],dp2[i+(1<<j)]);
}
}
//for (int i=0;i<4;i++) cout<<dp2[i].F<<' '<<dp2[i].S<<" ";cout<<endl;
for (int i=1;i<=n;i++){
for (int j=0;j<m;j++){
if (a[i]&(1<<j)) f[j]--;
}
int mask=0;
for (int j=0;j<m;j++){
if (f[j]!=n/2) mask|=(1<<j);
}
if (dp1[mask]>1 || (dp1[mask]==1 && (mask|a[i])!=mask)){
int x=0;
for (int j=0;j<m;j++) if (f[j]>=n/2) x++;
cout<<x<<endl;
for (int j=0;j<m;j++){
if (a[i]&(1<<j)) f[j]++;
}
continue;
}
int x=0;
if (dp2[mask].F!=__builtin_popcount(a[i]) || (mask|a[i])!=a[i]) x=dp2[mask].F;
else x=dp2[mask].S;
int y=0;
for (int j=0;j<m;j++) if (f[j]>=n/2) y++;
cout<<y-(x-__builtin_popcount(mask))<<endl;
for (int j=0;j<m;j++){
if (a[i]&(1<<j)) f[j]++;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |