# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
736075 | nguyentunglam | Council (JOI23_council) | C++17 | 895 ms | 38044 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>
#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)
# | 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... |