Submission #769608

#TimeUsernameProblemLanguageResultExecution timeMemory
769608MilosMilutinovicCouncil (JOI23_council)C++14
100 / 100
2164 ms164788 KiB
#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)

council.cpp: In function 'int main()':
council.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
council.cpp:20:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |             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...