結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー osa_kosa_k
提出日時 2015-07-27 01:32:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 1,509 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 61,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 17:19:42
合計ジャッジ時間 3,699 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 67 ms
4,380 KB
testcase_09 AC 15 ms
4,376 KB
testcase_10 AC 51 ms
4,380 KB
testcase_11 AC 37 ms
4,376 KB
testcase_12 AC 77 ms
4,380 KB
testcase_13 AC 83 ms
4,376 KB
testcase_14 AC 48 ms
4,380 KB
testcase_15 AC 90 ms
4,380 KB
testcase_16 AC 75 ms
4,380 KB
testcase_17 AC 82 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 21 ms
4,376 KB
testcase_21 AC 93 ms
4,380 KB
testcase_22 AC 93 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 57 ms
4,380 KB
testcase_29 AC 78 ms
4,380 KB
testcase_30 AC 69 ms
4,376 KB
testcase_31 AC 60 ms
4,376 KB
testcase_32 AC 74 ms
4,376 KB
testcase_33 AC 91 ms
4,380 KB
testcase_34 AC 89 ms
4,376 KB
testcase_35 AC 92 ms
4,380 KB
testcase_36 AC 93 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//Name: たのしい排他的論理和(HARD)
//Level: 3
//Category: 数学,行列,掃き出し法
//Note:

/**
 * 排他的論理和は Z/2 上でのベクトル合成と見ることができる。
 * したがって、与えられた数を用いて合成できる数の集合の大きさは、2^(行列の階数)に等しい。
 * 
 * オーダーは O((N + log(max A)) log(max A))。
 */
#include <iostream>
#include <bitset>
#include <vector>

using namespace std;

bool solve(bool first) {
    int N;
    if(!(cin >> N)) return false;

    vector<bitset<61>> matrix(N);
    for(int i = 0; i < N; ++i) {
        long long a;
        cin >> a;
        for(int j = 0; j < 61; ++j) {
            if(a & (1LL << j)) matrix[i][j] = 1;
        }
    }
    for(int i = 0; i < N; ++i) {
        int pivot = -1;
        for(int j = 0; j < 61; ++j) {
            if(matrix[i][j]) {
                pivot = j;
                break;
            }
        }
        if(pivot == -1) continue;
        for(int k = 0; k < N; ++k) {
            if(k == i) continue;
            if(matrix[k][pivot]) {
                matrix[k] ^= matrix[i];
            }
        }
    }
    int rank = 0;
    for(const auto &row : matrix) {
        if(row.count()) ++rank;
    }
    cout << (1LL << rank) << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}
0