#include <bits/stdc++.h>
#define maxn 300005
#define maxm 25
#define fi first
#define se second
using namespace std;
using ii = pair<int, int>;
int n, m;
int a[maxn][maxm];
namespace sub1 {
int cnt[maxm];
void mainProgram() {
int pivot = n/2;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cnt[j] += a[i][j];
for (int i1 = 1; i1 <= n; i1++) {
int ans = 0;
for (int j = 1; j <= m; j++) cnt[j] -= a[i1][j];
for (int i2 = 1; i2 <= n; i2++) {
if (i2 == i1) continue;
for (int j = 1; j <= m; j++) cnt[j] -= a[i2][j];
int ds = 0;
for (int j = 1; j <= m; j++) ds += (cnt[j] >= pivot);
ans = max(ans, ds);
for (int j = 1; j <= m; j++) cnt[j] += a[i2][j];
}
cout << ans << "\n";
for (int j = 1; j <= m; j++) cnt[j] += a[i1][j];
}
exit(0);
}
}
namespace sub2 {
int dem[1<<10], cnt[maxm], orz[maxn];
void mainProgram() {
int piv = n/2;
for (int i = 1; i <= n; i++) {
int mask = 0;
for (int j = 1; j <= m; j++) {
cnt[j] += a[i][j];
mask |= ((a[i][j])<<(j-1));
}
orz[i] = mask;
++dem[mask];
}
for (int i = 1; i <= n; i++) {
int ans = m;
for (int j = 1; j <= m; j++) cnt[j] -= a[i][j];
int mask = 0, ds = INT_MAX;
for (int j = 1; j <= m; j++)
if (cnt[j] < piv) --ans;
else if (cnt[j] == piv) mask |= (1<<(j-1));
for (int cmask = 0; cmask < (1<<m); cmask++) if (cnt[cmask]-(cmask==orz[i])) ds = min(ds, __builtin_popcount(cmask&mask));
for (int j = 1; j <= m; j++) cnt[j] += a[i][j];
cout << ans-ds << "\n";
}
exit(0);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j];
if (n <= 3000)
sub1::mainProgram();
sub2::mainProgram();
}
# | 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... |