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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//~ #define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define g4(a) get<4>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
using iiiii = tuple<int, int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
int N, M, X[300005], cnt[25];
bool b;
ii vec[(1 << 20) + 5][2], ans[(1 << 20) + 5][2];
inline void merge(ii a[], ii b[]) {
ii best = mp((int)1e9, -1), sndbest = mp((int)1e9, -1);
best = min(best, a[0]);
best = min(best, a[1]);
best = min(best, b[0]);
best = min(best, b[1]);
if (a[0].second != best.second) sndbest = min(sndbest, a[0]);
if (a[1].second != best.second) sndbest = min(sndbest, a[1]);
if (b[0].second != best.second) sndbest = min(sndbest, b[0]);
if (b[1].second != best.second) sndbest = min(sndbest, b[1]);
a[0] = best;
a[1] = sndbest;
}
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for (int i = 0; i < (1 << M); i++) {
for (int j = 0; j < 2; j++) {
vec[i][j] = ans[i][j] = mp((int)1e9, -1);
}
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j < M; j++) {
cin >> b;
X[i] |= (1 << j) * b;
cnt[j] += b;
}
if (vec[X[i]][0].first == (int)1e9) {
vec[X[i]][0] = mp(__builtin_popcount(X[i]), i);
} else if (vec[X[i]][1].first == (int)1e9) {
vec[X[i]][1] = mp(__builtin_popcount(X[i]), i);
}
}
for (int m = 0; m < (1 << M); m++) {
for (int s = m; s; s = (s - 1) & m) {
merge(vec[s], vec[m]);
}
merge(vec[0], vec[m]);
}
for (int m = 0; m < (1 << M); m++) {
for (int s = m; s; s = (s - 1) & m) {
// bm = s, k = m
int off = __builtin_popcount(s) - __builtin_popcount(m);
vec[s ^ m][0].first += off;
vec[s ^ m][1].first += off;
merge(ans[s], vec[s ^ m]);
vec[s ^ m][0].first -= off;
vec[s ^ m][1].first -= off;
}
}
for (int i = 1; i <= N; i++) {
int cur = 0, bm = 0;
for (int j = 0; j < M; j++) {
if (X[i] & (1 << j)) cnt[j]--;
}
for (int j = 0; j < M; j++) {
if (cnt[j] > N / 2) cur++;
else if (cnt[j] == N / 2) cur++, bm |= (1 << j);
}
if (bm) {
for (auto el : ans[bm]) {
if (el.second != i) {
cur -= el.first;
break;
}
}
}
cout << cur << '\n';
for (int j = 0; j < M; j++) {
if (X[i] & (1 << j)) cnt[j]++;
}
}
}
Compilation message (stderr)
council.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | main() {
| ^~~~
# | 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... |