#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 300000;
const int M = 17;
int n, m;
int a[N];
int pr[(1 << M)][3];
vector<int> v[(1 << M)];
void add(int i) {
int x = (((1 << m) - 1) ^ a[i]);
if((int)v[x].size() == 2) return;
for(int msk = x; msk > 0; msk = ((msk - 1) & x)) {
if(v[msk].size() == 2) continue;
if(v[msk].empty() || v[msk].back() != i)
v[msk].push_back(i);
}
}
int func(int msk, int i) {
return __builtin_popcount(msk & a[i]);
}
int T = (1 << 0) + (1 << 3) + (1 << 6) + (1 << 7) + (1 << 8) + (1 << 10);
void add1(int msk, int i) {
// if(msk == T) cout << i << ' ' << func(msk, i) << '\n';
if(pr[msk][0] == i || pr[msk][1] == i) return;
pr[msk][2] = i;
if(func(msk, pr[msk][2]) < func(msk, pr[msk][1]))
swap(pr[msk][1], pr[msk][2]);
if(func(msk, pr[msk][1]) < func(msk, pr[msk][0]))
swap(pr[msk][0], pr[msk][1]);
}
void print(int x) {
for(int j = 0; j < m; j++)
cout << ((x >> j) & 1);
cout << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> m;
vector<int> cnt(m);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
bool bt;
cin >> bt;
if(bt) {
a[i] |= (1 << j);
cnt[j]++;
}
}
add(i);
}
for(int msk = 0; msk < (1 << m); msk++) {
pr[msk][0] = 0; pr[msk][1] = 1;
for(int x = msk; x > 0; x = ((x - 1) & msk)) {
for(int c : v[x]) {
add1(msk, c);
}
}
}
for(int i = 0; i < n; i++) {
int msk = 0, ans = 0;
for(int j = 0; j < m; j++) {
int x = cnt[j] - (a[i] >> j & 1);
if(x >= n / 2) ans++;
if(x == n / 2)
msk |= (1 << j);
}
if(msk) {
int k = pr[msk][(pr[msk][0] == i)];
ans -= __builtin_popcount(msk & a[k]);
}
cout << ans << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3284 KB |
Output is correct |
2 |
Correct |
4 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3284 KB |
Output is correct |
4 |
Correct |
2 ms |
3284 KB |
Output is correct |
5 |
Runtime error |
5 ms |
6612 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3284 KB |
Output is correct |
2 |
Correct |
4 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3284 KB |
Output is correct |
4 |
Correct |
2 ms |
3284 KB |
Output is correct |
5 |
Runtime error |
5 ms |
6612 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3284 KB |
Output is correct |
2 |
Correct |
46 ms |
5116 KB |
Output is correct |
3 |
Correct |
50 ms |
3896 KB |
Output is correct |
4 |
Correct |
33 ms |
5172 KB |
Output is correct |
5 |
Correct |
47 ms |
5048 KB |
Output is correct |
6 |
Incorrect |
35 ms |
5052 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3284 KB |
Output is correct |
2 |
Correct |
46 ms |
5116 KB |
Output is correct |
3 |
Correct |
50 ms |
3896 KB |
Output is correct |
4 |
Correct |
33 ms |
5172 KB |
Output is correct |
5 |
Correct |
47 ms |
5048 KB |
Output is correct |
6 |
Incorrect |
35 ms |
5052 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3284 KB |
Output is correct |
2 |
Correct |
46 ms |
5116 KB |
Output is correct |
3 |
Correct |
50 ms |
3896 KB |
Output is correct |
4 |
Correct |
33 ms |
5172 KB |
Output is correct |
5 |
Correct |
47 ms |
5048 KB |
Output is correct |
6 |
Incorrect |
35 ms |
5052 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3284 KB |
Output is correct |
2 |
Correct |
46 ms |
5116 KB |
Output is correct |
3 |
Correct |
50 ms |
3896 KB |
Output is correct |
4 |
Correct |
33 ms |
5172 KB |
Output is correct |
5 |
Correct |
47 ms |
5048 KB |
Output is correct |
6 |
Incorrect |
35 ms |
5052 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3284 KB |
Output is correct |
2 |
Correct |
4 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3284 KB |
Output is correct |
4 |
Correct |
2 ms |
3284 KB |
Output is correct |
5 |
Runtime error |
5 ms |
6612 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |