Submission #769599

#TimeUsernameProblemLanguageResultExecution timeMemory
769599MilosMilutinovicCouncil (JOI23_council)C++14
6 / 100
4074 ms65140 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int M = 21;
int n, m, a[N][M], b[N][M], v[N], cnt[M], bst[1 << M], ans[N];
void dfs(int i, int x) {
    for (int j = 0; j < (1 << (m + 1)); j++) {
        if (__builtin_popcount(bst[j] & j) > __builtin_popcount(x & j)) {
            bst[j] = 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];
        }
    }
    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(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)

council.cpp: In function 'int main()':
council.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
council.cpp:17:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |             scanf("%d", &a[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...