답안 #877633

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877633 2023-11-23T11:30:47 Z LucaIlie Council (JOI23_council) C++17
0 / 100
1 ms 2396 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 3e5;
const int MAX_M = 20;

int countVc[1 << MAX_M], ans[1 << MAX_M];
int vote[MAX_N], pro[MAX_M];

int main() {
    int n, m;

    cin >> n >> m;
    for ( int i = 0; i < n; i++ ) {
        for ( int b = 0; b < m; b++ ) {
            int x;
            cin >> x;
            vote[i] += (x << b);
            pro[b] += x;
        }
        countVc[vote[i]]++;
    }

    for ( int b = 0; b < m; b++ ) {
        for ( int mask = 0; mask < (1 << m); mask++ ) {
            if ( (mask >> b) & 1 )
                countVc[mask] += countVc[mask - (1 << b)];
        }
    }

    for ( int i = 0; i < n; i++ ) {
        vector<int> bits;
        int ap = 0, maskBits = 0;
        for ( int b = 0; b < m; b++ ) {
            int x = pro[b] - ((vote[i] >> b) & 1);
            if ( x > n / 2 )
                ap++;
            if ( x == n / 2 ) {
                bits.push_back( b );
                maskBits += (1 << b);
            }
        }

        int maxAp = 0;
        if ( ans[maskBits] == 0 ) {
            for ( int mask = 0; mask < (1 << bits.size()); mask++ ) {
                int vc = (1 << m) - 1;
                for ( int b = 0; b < bits.size(); b++ ) {
                    if ( (mask >> b) & 1 )
                        vc -= (1 << bits[b]);
                }
                if ( countVc[vc] >= 2 || (((vote[i] & vc) != vote[i]) && countVc[vc] >= 1) )
                    maxAp = max( maxAp, __builtin_popcount( mask ) );
            }
            ans[maskBits] = maxAp + 1;
        } else
            maxAp = ans[maskBits] + 1;

        cout << ap + maxAp << "\n";
    }

    return 0;
}

Compilation message

council.cpp: In function 'int main()':
council.cpp:49:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |                 for ( int b = 0; b < bits.size(); b++ ) {
      |                                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -