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 MAX_N = 3e5;
const int MAX_M = 20;
struct aa {
int x, y;
void operator += ( const aa &a ) {
if ( x == -1 ) {
x = a.x;
y = a.y;
} else if ( y == -1 )
y = a.x;
}
};
struct bb {
int min1, x, min2, y;
void operator += ( const bb &b ) {
if ( b.min1 < min1 ) {
if ( x != b.x ) {
min2 = min1;
y = x;
}
min1 = b.min1;
x = b.x;
} else if ( b.min1 < min2 && x != b.x ) {
min2 = b.min1;
y = b.x;
}
if ( b.min2 < min1 ) {
if ( x != b.y ) {
min2 = min1;
y = x;
}
min1 = b.min2;
x = b.y;
} else if ( b.min2 < min2 && x != b.y ) {
min2 = b.min2;
y = b.y;
}
}
};
aa countVc1[1 << MAX_M];
bb countVc2[1 << MAX_M];
int vote[MAX_N], pro[MAX_M];
int main() {
int n, m;
cin >> n >> m;
for ( int mask = 0; mask < (1 << m); mask++ )
countVc1[mask] = { -1, -1 };
for ( int i = 0; i < n; i++ ) {
for ( int b = 0; b < m; b++ ) {
int x;
cin >> x;
vote[i] += (x << b);
pro[b] += x;
}
countVc1[vote[i]] += { i, -1 };
}
for ( int b = 0; b < m; b++ ) {
for ( int mask = 0; mask < (1 << m); mask++ ) {
if ( (mask >> b) & 1 )
countVc1[mask] += countVc1[mask - (1 << b)];
}
}
for ( int mask = 0; mask < (1 << m); mask++ ) {
int x = countVc1[mask].x;
int y = countVc1[mask].y;
int mx = (x == -1 ? m + 1 : __builtin_popcount( mask ));
int my = (y == -1 ? m + 1 : __builtin_popcount( mask ));
countVc2[mask] = { mx, x, my, y };
}
for ( int b = 0; b < m; b++ ) {
for ( int mask = (1 << m) - 1; mask >= 0; mask-- ) {
if ( ((mask >> b) & 1) == 0 )
countVc2[mask] += countVc2[mask + (1 << b)];
}
}
for ( int i = 0; i < n; i++ ) {
vector<int> bits;
int mask = (1 << m) - 1, ap = 0, k = 0;
for ( int b = 0; b < m; b++ ) {
int x = pro[b] - ((vote[i] >> b) & 1);
if ( x > n / 2 )
ap++;
if ( x == n / 2 ) {
mask -= (1 << b);
k++;
}
}
if ( countVc2[mask].x == -1 )
cout << ap;
else if ( countVc2[mask].x == i ) {
if ( countVc2[mask].y == -1 )
cout << ap;
else
cout << ap + k - (countVc2[mask].min2 - __builtin_popcount( mask ));
} else
cout << ap + k - (countVc2[mask].min1 - __builtin_popcount( mask ));
cout << "\n";
}
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... |