結果

問題 No.183 たのしい排他的論理和(EASY)
ユーザー rogi52rogi52
提出日時 2022-08-13 12:11:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,194 bytes
コンパイル時間 1,946 ms
コンパイル使用メモリ 193,436 KB
最終ジャッジ日時 2025-01-30 22:09:46
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const int MAX_ROW = 5050;
const int MAX_COL = 15;
struct BitMatrix {
    int H,W;
    bitset< MAX_COL > val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset< MAX_COL > & operator[] (int i) { return val[i]; }
};

int Gauss_Jordan(BitMatrix &A, bool is_extended = false) {
    int rank = 0;
    for(int col = 0; col < A.W; ++col) {
        if(is_extended && col == A.W - 1) break;
        int pivot = -1;
        for(int row = rank; row < A.H; ++row) {
            if(A[row][col]) {
                pivot = row;
                break;
            }
        }
        if(pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for(int row = 0; row < A.H; ++row) {
            if(row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    BitMatrix A(N, 15);
    rep(i,N) {
        int a; cin >> a;
        rep(j,15) A[i][j] = (a & (1 << j));
    }
    int rank = Gauss_Jordan(A);
    cout << (1LL << rank) << endl;
}
0