제출 #1109475

#제출 시각아이디문제언어결과실행 시간메모리
1109475vladiliusCouncil (JOI23_council)C++17
33 / 100
4091 ms87212 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, m; cin>>n>>m;
    vector<vector<bool>> a(n + 1, vector<bool>(m + 1));
    vector<int> A[m + 1], B[n + 1];
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            bool b; cin>>b;
            if (b){
                A[j].pb(i);
                B[i].pb(j);
            }
            a[i][j] = b;
        }
    }
    
    vector<int> x(m + 1);
    for (int i = 1; i <= m; i++) x[i] = (int) A[i].size();
    
    vector<int> tw(m + 1); tw[0] = 1;
    for (int i = 1; i <= m; i++){
        tw[i] = tw[i - 1] * 2;
    }
    vector<int> y(n + 1), out(n + 1), p1(n + 1), p2(n + 2), d[tw[m]];
    
    const int M = n / 2;
    vector<int> all;
    
    for (int i = 1; i <= n; i++){
        for (int j: B[i]) x[j]--;
        
        all.clear();
        int f = m;
        for (int j = 1; j <= m; j++){
            if (x[j] != M){
                f -= (x[j] < M);
                continue;
            }
            all.pb(j);
        }
        
        int v = 0;
        for (int j: all){
            v += tw[j - 1];
        }
        
        d[v].pb(i);
        out[i] = f;

        for (int j: B[i]) x[j]++;
    }
    
    function<void(int, int)> rec = [&](int i, int v){
        if (i == m + 1){
            p1[0] = 1e9;
            for (int j = 1; j <= n; j++){
                p1[j] = min(p1[j - 1], y[j]);
            }
            p2[n + 1] = 1e9;
            for (int j = n; j > 0; j--){
                p2[j] = min(p2[j + 1], y[j]);
            }
            
            for (int k: d[v]){
                out[k] -= min(p1[k - 1], p2[k + 1]);
            }
            return;
        }
        rec(i + 1, v);
        for (int j: A[i]){
            y[j]++;
        }
        rec(i + 1, v + tw[i - 1]);
        for (int j: A[i]){
            y[j]--;
        }
    };
    rec(1, 0);
    
    for (int i = 1; i <= n; i++){
        cout<<out[i]<<"\n";
    }
}
#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...