제출 #893370

#제출 시각아이디문제언어결과실행 시간메모리
893370ksujay2Council (JOI23_council)C++17
33 / 100
3932 ms16180 KiB
#include <bits/stdc++.h>
using namespace std;
const int BS = 550;
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N, M; cin >> N >> M;
    vector<int> A(N);
    vector<int> cnt(M);
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            int a; cin >> a;
            A[i] += a << j;
            cnt[j] += a;
        }
    }
    vector<int> D;
    for(int i = 0; i < N; i++) {
        if(i % BS == 0) {
            D = vector<int>(1 << M, -1);
            queue<int> rep, fut;
            for(int j = 0; j < N; j++) {
                if(j < i || i + BS <= j) {
                    D[A[j]] = 0;
                    fut.push(A[j]);
                }
            }
            while(rep.size() + fut.size() > 0) {
                int s;
                if(rep.size() > 0) s = rep.front(), rep.pop();
                else s = fut.front(), fut.pop();
                for(int j = 0; j < M; j++) {
                    if(D[s ^ (1 << j)] == -1) {
                        if((s & (1 << j)) > 0) {
                            D[s ^ (1 << j)] = D[s] + 1;
                            fut.push(s ^ (1 << j));
                        } else {
                            D[s ^ (1 << j)] = D[s];
                            rep.push(s ^ (1 << j));
                        }
                    }
                }
            }
        }
        int v = 0;
        int ans = 0;
        for(int j = 0; j < M; j++) {
            int c = (cnt[j] - ((A[i] & (1 << j)) > 0));
            if(c == N / 2) {
                v ^= 1 << j;
            }
            if(c >= N / 2) ans++;
        }
        int best = D[(1 << M) - 1 - v];
        if(best == -1) best = 1e9;
        for(int j = i - (i % BS); j < (i + BS - (i % BS)) && j < N; j++) {
            if(j != i) {
                best = min(best, __popcount(A[j] - (A[j] & (~v))));
            }
        }
        cout << ans - best << endl;
    }
}
#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...