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>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m; cin >> n >> m;
vector <vector<int>> a(n, vector <int> (m));
for ( auto &u: a ){
for ( auto &v: u ) cin >> v;
}
vector <int> cnt(m);
for ( int i = 0; i < n; i++ ){
for ( int j = 0; j < m; j++ ){
cnt[j] += a[i][j];
}
}
int tot = 0;
for ( auto &x: cnt ){
tot += (x >= n / 2);
}
const int S = 1 << m;
vector <ar<int,2>> us(S, {-1, -1});
for ( int i = 0; i < n; i++ ){
int b = 0;
for ( int j = 0; j < m; j++ ){
b |= a[i][j] << j;
}
if ( us[b][0] != -1 ){
swap(us[b][0], us[b][1]);
}
us[b][0] = i;
}
if ( m <= 14 ){
vector <vector<ar<int,2>>> lst(S, vector <ar<int,2>> (m + 1, {-1, -1}));
auto ins = [&](auto &a, int u){
if ( a[0] == -1 ){
a[0] = u;
} else if ( a[1] == -1 ){
a[1] = u;
} else if ( a[0] == a[1] ){
a[0] = u;
}
};
for ( int i = 0; i < S; i++ ){
for ( int j = 0; j < S; j++ ){
int b = __builtin_popcount(i & j);
if ( us[j][0] != -1 ){
ins(lst[i][b], us[j][0]);
}
if ( us[j][1] != -1 ){
ins(lst[i][b], us[j][1]);
}
}
}
for ( auto &u: lst ){
for ( auto &v: u ){
sort(all(v));
}
}
for ( int i = 0; i < n; i++ ){
auto tmp = cnt;
int b = 0, q = tot;
for ( int j = 0; j < m; j++ ){
if ( a[i][j] && tmp[j] == n / 2 ){
--q;
} tmp[j] -= a[i][j];
if ( tmp[j] == n / 2 ){
b |= 1 << j;
}
}
for ( int j = 0; j <= m; j++ ){
auto &tmp = lst[b][j];
bool flag = false;
for ( auto k: {0, 1} ){
if ( tmp[k] != -1 && tmp[k] != i ){
flag = true;
}
}
if ( flag ){
q -= j;
break;
}
}
cout << q << ln;
}
} else{
for ( int i = 0; i < n; i++ ){
int mx = 0, q = tot;
auto tmp = cnt;
for ( int j = 0; j < m; j++ ){
if ( a[i][j] && cnt[j] == n / 2 ){
--q;
} cnt[j] -= a[i][j];
}
for ( int j = 0; j < n; j++ ){
if ( j == i ) continue;
int tq = q;
for ( int k = 0; k < m; k++ ){
if ( a[j][k] && cnt[k] == n / 2 ){
--tq;
}
}
chmax(mx, tq);
}
cout << mx << ln;
swap(tmp, cnt);
}
}
cout << '\n';
}
# | 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... |