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;
const int BS = 550;
const int INF = 1e9;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int N, M; cin >> N >> M;
vector<int> A(N);
vector<int> cnt(M);
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
int a; cin >> a;
A[i] += a << j;
cnt[j] += a;
}
}
vector<int> D;
for(int i = 0; i < N; i++) {
if(i % BS == 0) {
D = vector<int>(1 << M, INF);
queue<int> q;
for(int j = 0; j < N; j++) {
if(j < i || i + BS <= j) {
if(D[A[j]] > 0) {
D[A[j]] = 0;
q.push(A[j]);
}
}
}
function<void(int)> dfs = [&] (int s) {
for(int j = 0; j < M; j++) {
if(D[s ^ (1 << j)] == INF) {
if((s & (1 << j)) > 0) {
D[s ^ (1 << j)] = D[s] + 1;
q.push(s ^ (1 << j));
} else {
D[s ^ (1 << j)] = D[s];
dfs(s ^ (1 << j));
}
}
}
};
while(q.size() > 0) {
int s = q.front();
dfs(s);
}
}
int v = (1 << M) - 1;
int ans = 0;
for(int j = 0; j < M; j++) {
int c = (cnt[j] - ((A[i] & (1 << j)) > 0));
if(c == N / 2) {
v ^= 1 << j;
}
if(c >= N / 2) ans++;
}
int best = D[v];
for(int j = i - (i % BS); j < (i - (i % BS) + BS) && j < N; j++) {
if(j != i) {
best = min(best, __popcount(A[j] ^ (A[j] & v)));
}
}
cout << ans - best << '\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... |