# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
810941 | lukameladze | Council (JOI23_council) | C++17 | 672 ms | 38724 KiB |
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;
#define f first
#define s second
#define ll long long
//#define int long long
#define pii pair <int, int>
#define pb push_back
const int N = 2e6 + 5, inf = 1e9;
int n, m, a[N], cnt[N], raod[N];
pii idx[N], dp[N][2];
void upd(int idx, int vl) {
if (!vl) return ;
int res = __builtin_popcount(idx & a[vl]);
if (res < dp[idx][0].f) {
dp[idx][1] = dp[idx][0];
dp[idx][0] = {res, vl};
} else if (res < dp[idx][1].f && vl != dp[idx][0].s) {
dp[idx][1] = {res, vl};
}
}
signed main() {
cin>>n>>m;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) {
char ch; cin>>ch;
if (ch == '1') a[i] |= (1<<j),cnt[j]++;
}
}
for (int i = 1; i <= n; i++) {
int op = a[i] ^ ((1<<m) - 1);
int ff = 0;
if (!idx[op].f) idx[op].f = i;
else idx[op].s = i;
}
for (int i = (1<<m) - 1; i >= 0; i--) {
if (idx[i].f && idx[i].s) continue;
for (int j = 0; j < m; j++) {
if ((1<<j)&i) continue;
if (!idx[i].f) {
if (idx[i ^ (1<<j)].f) idx[i].f = idx[i ^ (1<<j)].f;
}
if (!idx[i].s) {
if (idx[i ^ (1<<j)].f && idx[i ^ (1<<j)].f != idx[i].f) {
idx[i].s = idx[i ^ (1<<j)].f;
}
if (idx[i ^ (1<<j)].s && idx[i ^ (1<<j)].s != idx[i].f) {
idx[i].s = idx[i ^ (1<<j)].s;
}
}
}
}
for (int i = 0; i < (1<<m); i++) {
dp[i][0] = dp[i][1] = {inf, 0};
if (idx[i].f) upd(i, idx[i].f); if (idx[i].s) upd(i, idx[i].s); // tu 0 aqvs saerto
for (int j = 0; j < m; j++) {
if ((1<<j)&i) { // tu me-j aqvs saerto
upd(i, dp[i ^ (1<<j)][0].s);
upd(i, dp[i ^ (1<<j)][1].s);
}
}
}
for (int i = 1; i <= n; i++) {
int res = 0, mask = 0;
for (int j = 0; j < m; j++) {
if ((1<<j)&a[i]) cnt[j]--;
if (cnt[j] == n / 2) mask |= (1<<j);//, cout<<j<<" ";
if (cnt[j] >= n / 2) res++;
if ((1<<j)&a[i]) cnt[j]++;
}
//cout<<res<<"\n";
if (dp[mask][0].s != i) cout<<res - dp[mask][0].f<<"\n";
else cout<<res - dp[mask][1].f<<"\n";
}
}
Compilation message (stderr)
# | 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... |