# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
769608 | MilosMilutinovic | Council (JOI23_council) | C++14 | 2164 ms | 164788 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;
const int N = 3e5 + 10;
const int M = 22;
int n, m, a[N][M], b[N][M], v[N], cnt[M], bst[1 << M], ans[N];
void dfs(int i, int x) {
bst[i] = x;
for (int j = 1; j <= m; j++) {
int ni = (i ^ (1 << j));
if (__builtin_popcount(bst[ni] & ni) > __builtin_popcount(x & ni)) {
bst[ni] = x;
dfs(ni, x);
}
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d", &a[i][j]);
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cnt[j] += a[i][j];
}
}
int full_mask = 0;
for (int j = 1; j <= m; j++) {
full_mask += (1 << j);
}
for (int iter = 1; iter <= 2; iter++) {
for (int i = 1; i <= n; i++) {
v[i] = 0;
for (int j = 1; j <= m; j++) {
if (a[i][j] == 1) {
v[i] += (1 << j);
}
}
}
for (int i = 0; i < (1 << M); i++) {
bst[i] = i;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cnt[j] -= a[i][j];
}
int msk = 0, good = 0;
for (int j = 1; j <= m; j++) {
if (cnt[j] == (n / 2)) {
msk ^= (1 << j);
}
if (cnt[j] >= (n / 2)) {
good += 1;
}
}
ans[iter == 1 ? i : n - i + 1] = max(ans[iter == 1 ? i : n - i + 1], good - __builtin_popcount(bst[msk] & msk));
for (int j = 1; j <= m; j++) {
cnt[j] += a[i][j];
}
dfs(full_mask ^ v[i], v[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
b[n - i + 1][j] = a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = b[i][j];
}
}
}
for (int i = 1; i <= n; i++) {
printf("%d\n", ans[i]);
}
return 0;
}
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... |