답안 #795092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795092 2023-07-27T06:28:36 Z vjudge1 Council (JOI23_council) C++17
0 / 100
57 ms 58660 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 3000000;
const int M = 17;

int n, m;

int a[N];
int pr[(1 << M)][3];
vector<int> v[(1 << M)];

void add(int i) {
    int x = (((1 << m) - 1) ^ a[i]);
    if((int)v[x].size() > 1) return;
    for(int msk = x; msk > 0; msk = ((msk - 1) & x)) {
        if(v[msk].size() < 2 && (v[msk].empty() || v[msk][0] != i)) 
            v[msk].push_back(i);
    }
}


int func(int msk, int i) {
    return __builtin_popcount(msk & a[i]);
}
int T = (1 << 0) + (1 << 3) + (1 << 6) + (1 << 7) + (1 << 8) + (1 << 10);
void add1(int msk, int i) {
    // if(msk == T) cout << i << ' ' << func(msk, i) << '\n';
    if(pr[msk][0] == i || pr[msk][1] == i) return;
    pr[msk][2] = i;
    if(func(msk, pr[msk][2]) < func(msk, pr[msk][1])) 
        swap(pr[msk][1], pr[msk][2]);
    if(func(msk, pr[msk][1]) < func(msk, pr[msk][0])) 
        swap(pr[msk][0], pr[msk][1]);
} 

void print(int x) {
    for(int j = 0; j < m; j++) 
        cout << ((x >> j) & 1);
    cout << '\n';
}

vector<int> cnt(M);
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            bool bt;
            cin >> bt;
            if(bt) {
                a[i] |= (1 << j);
                cnt[j]++;
            }
        }
        add(i);
    }
    for(int msk = 0; msk < (1 << m); msk++) {
        pr[msk][0] = 0; pr[msk][1] = 1;
        for(int x = msk; x > 0; x = ((x - 1) & msk)) {
            for(int c : v[x]) {
                add1(msk, c);
            }
        }
    }
    // 100100111010
    // cout << pr[T][0] << ' ' << pr[T][1] << '\n';
    // cout << func(T, pr[T][0]) << ' ' << func(T, pr[T][1]) << '\n';
    for(int i = 0; i < n; i++) {
        int msk = 0, ans = 0;
        for(int j = 0; j < m; j++) {
            int x = cnt[j] - (a[i] >> j & 1);
            if(x >= n / 2) ans++;
            if(x == n / 2) 
                msk |= (1 << j);
        }
        // for(int j = 0; j < m; j++) 
        //     cout << ((msk >> j) & 1);
        // cout << ' ' << pr[msk][1] << '\n';  
        if(msk) {
            int k = pr[msk][(pr[msk][0] == i)];
            ans -= __builtin_popcount(msk & a[k]);
        } 
        cout << ans << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 4 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Runtime error 57 ms 58660 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 4 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Runtime error 57 ms 58660 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 50 ms 5624 KB Output is correct
3 Correct 44 ms 4300 KB Output is correct
4 Correct 32 ms 5348 KB Output is correct
5 Correct 49 ms 5504 KB Output is correct
6 Incorrect 35 ms 5364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 50 ms 5624 KB Output is correct
3 Correct 44 ms 4300 KB Output is correct
4 Correct 32 ms 5348 KB Output is correct
5 Correct 49 ms 5504 KB Output is correct
6 Incorrect 35 ms 5364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 50 ms 5624 KB Output is correct
3 Correct 44 ms 4300 KB Output is correct
4 Correct 32 ms 5348 KB Output is correct
5 Correct 49 ms 5504 KB Output is correct
6 Incorrect 35 ms 5364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 50 ms 5624 KB Output is correct
3 Correct 44 ms 4300 KB Output is correct
4 Correct 32 ms 5348 KB Output is correct
5 Correct 49 ms 5504 KB Output is correct
6 Incorrect 35 ms 5364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 4 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Runtime error 57 ms 58660 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -