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 = 800;
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;
auto dp = [&] () {
for(int i = 0; i < (1 << M); i++) {
for(int j = 0; j < M; j++) {
if((i & (1 << j)) > 0) {
D[i] = min(D[i], D[i ^ (1 << j)]);
}
}
}
for(int i = (1 << M) - 1; i >= 0; i--) {
for(int j = 0; j < M; j++) {
if((i & (1 << j)) == 0) {
D[i] = min(D[i], D[i ^ (1 << j)] + 1);
}
}
}
};
for(int i = 0; i < N; i++) {
if(i % BS == 0) {
D = vector<int>(1 << M, INF);
for(int j = 0; j < N; j++) {
if(j < i || i + BS <= j) {
D[A[j]] = 0;
}
}
dp();
}
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... |