結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー drken1215drken1215
提出日時 2019-03-20 17:43:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 5,000 ms
コード長 2,103 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 73,624 KB
実行使用メモリ 4,892 KB
最終ジャッジ日時 2023-09-17 17:48:31
合計ジャッジ時間 4,141 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,420 KB
testcase_08 AC 76 ms
4,380 KB
testcase_09 AC 19 ms
4,376 KB
testcase_10 AC 59 ms
4,620 KB
testcase_11 AC 43 ms
4,380 KB
testcase_12 AC 87 ms
4,764 KB
testcase_13 AC 94 ms
4,636 KB
testcase_14 AC 55 ms
4,380 KB
testcase_15 AC 102 ms
4,704 KB
testcase_16 AC 85 ms
4,764 KB
testcase_17 AC 92 ms
4,768 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 28 ms
4,712 KB
testcase_21 AC 104 ms
4,636 KB
testcase_22 AC 105 ms
4,892 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,416 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 64 ms
4,376 KB
testcase_29 AC 90 ms
4,700 KB
testcase_30 AC 78 ms
4,708 KB
testcase_31 AC 68 ms
4,380 KB
testcase_32 AC 84 ms
4,636 KB
testcase_33 AC 102 ms
4,572 KB
testcase_34 AC 100 ms
4,632 KB
testcase_35 AC 103 ms
4,636 KB
testcase_36 AC 103 ms
4,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl


const int MAX_ROW = 65; // to be set appropriately
const int MAX_COL = 110000; // to be set appropriately
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];}
};

ostream& operator << (ostream& s, BitMatrix A) {
    s << endl; 
    for (int i = 0; i < A.H; ++i) {
        for (int j = 0; j < A.W; ++j) {
            s << A[i][j] << ", ";
        }
        s << endl;
    }
    return s;
}

int GaussJordan(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 linear_equation(BitMatrix A, vector<int> b, vector<int> &res) {
    int m = A.H, n = A.W;
    BitMatrix M(m, n + 1);
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
        M[i][n] = b[i];
    }
    int rank = GaussJordan(M, true);

    // check if it has no solution
    for (int row = rank; row < m; ++row) if (M[row][n]) return -1;

    // answer
    res.assign(n, 0);
    for (int i = 0; i < rank; ++i) res[i] = M[i][n];
    return rank;
}


    
int main() {
    int N; cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    const int DIGIT = 61;
    BitMatrix A(DIGIT, N);
    for (int d = 0; d < DIGIT; ++d) {
        for (int i = 0; i < N; ++i) {
            if (a[i] & (1LL<<d)) A[d][i] = 1;
        }
    }
    int rank = GaussJordan(A);
    cout << (1LL<<rank) << endl;
}
0