제출 #931892

#제출 시각아이디문제언어결과실행 시간메모리
931892alextodoranCouncil (JOI23_council)C++17
33 / 100
4054 ms17576 KiB
/**
 _  _   __  _ _ _  _  _ _
 |a  ||t  ||o    d | |o  |
| __    _| | _ | __|  _ |
| __ |/_  | __  /__\ / _\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 300000;
const int M_MAX = 20;

int N, M;
bool vote[N_MAX][M_MAX];
int total[M_MAX];

struct Nirvana {
    int max1, max1i;
    int max2, max2i;
};

Nirvana max (const Nirvana &a, const Nirvana &b) {
    Nirvana c;
    c.max1 = max(a.max1, b.max1);
    c.max1i = (c.max1 == a.max1 ? a.max1i : b.max1i);
    c.max2 = 0; c.max2i = 0;
    if (a.max1 > c.max2 && a.max1i != c.max1i) {
        c.max2 = a.max1; c.max2i = a.max1i;
    }
    if (b.max1 > c.max2 && b.max1i != c.max1i) {
        c.max2 = b.max1; c.max2i = b.max1i;
    }
    if (a.max2 > c.max2 && a.max2i != c.max1i) {
        c.max2 = a.max2; c.max2i = a.max2i;
    }
    if (b.max2 > c.max2 && b.max2i != c.max1i) {
        c.max2 = b.max2; c.max2i = b.max2i;
    }
    return c;
}

Nirvana dp[1 << M_MAX];

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        int mask = 0;
        for (int j = 0; j < M; j++) {
            cin >> vote[i][j];
            mask ^= (!vote[i][j] << j);
            total[j] += vote[i][j];
        }
        int sub = mask;
        while (true) {
            dp[sub] = max(dp[sub], Nirvana{__builtin_popcount(sub), i, 0, 0});
            sub--;
            if (sub < 0) {
                break;
            }
            sub &= mask;
        }
    }
    for (int j = 0; j < M; j++) {
        int bit = (1 << j);
        for (int mask = bit; mask < (1 << M); mask = ((mask + 1) | bit)) {
            dp[mask] = max(dp[mask], dp[mask ^ bit]);
        }
    }
    for (int i = 0; i < N; i++) {
        int cnt_ok = 0;
        int mask_bonus = 0;
        for (int j = 0; j < M; j++) {
            if ((total[j] - vote[i][j] - 1) * 2 > N - 2) {
                cnt_ok++;
            } else if ((total[j] - vote[i][j] - 0) * 2 > N - 2) {
                mask_bonus ^= (1 << j);
            }
        }
        Nirvana a = dp[mask_bonus];
        cout << cnt_ok + (a.max1i != i ? a.max1 : a.max2) << "\n";
    }

    return 0;
}
#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...