/**
_ _ __ _ _ _ _ _ _
|a ||t ||o d | |o |
| __ _| | _ | __| _ |
| __ |/_ | __ /__\ / _\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 300000;
const int M_MAX = 20;
int N, M;
bool vote[N_MAX][M_MAX];
int total[M_MAX];
int dp[1 << M_MAX];
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
for (int i = 0; i < N; i++) {
int mask = 0;
for (int j = 0; j < M; j++) {
cin >> vote[i][j];
mask ^= (!vote[i][j] << j);
total[j] += vote[i][j];
}
int sub = mask;
while (true) {
dp[sub] = 1;
sub--;
if (sub < 0) {
break;
}
sub &= mask;
}
}
for (int mask = 0; mask < (1 << M); mask++) {
dp[mask] = __builtin_popcount(mask);
}
for (int j = 0; j < M; j++) {
int bit = (1 << j);
for (int mask = bit; mask < (1 << M); mask = ((mask + 1) | bit)) {
dp[mask] = max(dp[mask], dp[mask ^ bit]);
}
}
for (int i = 0; i < N; i++) {
int cnt_ok = 0;
int mask_bonus = 0;
for (int j = 0; j < M; j++) {
if ((total[j] - vote[i][j] - 1) * 2 > N - 2) {
cnt_ok++;
} else if ((total[j] - vote[i][j] - 0) * 2 > N - 2) {
mask_bonus ^= (1 << j);
}
}
cout << cnt_ok + dp[mask_bonus] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |