Submission #736075

#TimeUsernameProblemLanguageResultExecution timeMemory
736075nguyentunglamCouncil (JOI23_council)C++17
100 / 100
895 ms38044 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 3e5 + 10, M = 20; bool a[N][M]; int f[2][1 << M], g[N], bit[1 << M], vote[M]; pair<int, int> dp[2][1 << M]; void add(int mask, int idx) { if (idx == -1) return; f[1][mask] = f[0][mask]; f[0][mask] = idx; } void up(int mask, pair<int, int> tmp) { if (tmp.se == dp[1][mask].se || tmp.se == dp[0][mask].se) return; dp[1][mask] = max(dp[1][mask], tmp); if (dp[0][mask] < dp[1][mask]) swap(dp[0][mask], dp[1][mask]); } int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n, m; cin >> n >> m; for(int i = 0; i < (1 << m); i++) { bit[i] = __builtin_popcount(i); f[0][i] = f[1][i] = -1; } for(int i = 1; i <= n; i++) { for(int j = 0; j < m; j++) cin >> a[i][j], vote[j] += a[i][j]; for(int j = 0; j < m; j++) if (!a[i][j]) g[i] |= (1 << j); add(g[i], i); } for(int i = 0; i < m; i++) for(int mask = (1 << m) - 1; mask >= 0; mask--) { if (!(mask >> i & 1)) { add(mask, f[0][mask | (1 << i)]); add(mask, f[1][mask | (1 << i)]); } } for(int i = 0; i < m; i++) for(int mask = 0; mask < (1 << m); mask++) { if (f[0][mask] != -1) up(mask, make_pair(bit[mask], f[0][mask])); if (f[1][mask] != -1) up(mask, make_pair(bit[mask], f[1][mask])); if (mask >> i & 1) { up(mask, dp[0][mask ^ (1 << i)]); up(mask, dp[1][mask ^ (1 << i)]); } } for(int i = 1; i <= n; i++) { int mask = 0, ans = 0; for(int j = 0; j < m; j++) { vote[j] -= a[i][j]; if (vote[j] == n / 2) mask |= (1 << j); if (vote[j] > n / 2) ans++; vote[j] += a[i][j]; } if (dp[0][mask].se == i) cout << ans + dp[1][mask].fi; else cout << ans + dp[0][mask].fi; cout << endl; } }

Compilation message (stderr)

council.cpp: In function 'int main()':
council.cpp:27:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:28:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:31:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:32:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...