Submission #17417188


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;

//typedef
typedef unsigned int UINT;
typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef tuple<LL, LL, LL> TLL3;
typedef tuple<LL, LL, LL, LL> TLL4;
typedef set<LL, greater<LL> > setdownLL;
#define PQ priority_queue
typedef PQ<LL, vector<LL>, greater<LL> > pqupLL;
//container utill
#define ALL(v) (v).begin(),(v).end()
#define CR [](auto element1, auto element2){return element1>element2;}
#define LB lower_bound
#define UP upper_bound
#define PB push_back
#define MP make_pair
#define MT make_tuple
//constant
#define PI 3.141592653589793

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

inline BitMatrix operator * (BitMatrix A, BitMatrix B) {
    BitMatrix R(A.H, B.W);
    BitMatrix tB(B.W, B.H);
    for (int i = 0; i < tB.H; ++i) for (int j = 0; j < tB.W; ++j) tB[i][j] = B[j][i];
    for (int i = 0; i < R.H; ++i) for (int j = 0; j < R.W; ++j) R[i][j] = ((A[i] & tB[j]).count() & 1);
    return R;
}

inline BitMatrix pow(BitMatrix A, long long n) {
    BitMatrix R(A.H, A.H);
    for (int i = 0; i < A.H; ++i) R[i][i] = 1;
    while (n > 0) {
        if (n & 1) R = R * A;
        A = A * A;
        n >>= 1;
    }
    return R;
}

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;
}


const int MOD = 1000000007;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    //input
    LL N,K;
    cin >> N >> K;
    LL A[N];
    LL i,j;
    for(i=0; i<N; i++){
        cin >> A[i];
    }

    //calc
    vector<int> b;
    for(i=0; i<20; i++){
        if(K%2==1){
            b.PB(1);
        }else{
            b.PB(0);
        }
        K/=2;
    }
    BitMatrix AA(20,N);
    for(j=0; j<N; j++){
        for(i=0; i<20; i++){
            if(A[j]%2==1){
                AA[i][j]=1;
            }else{
                AA[i][j]=0;
            }
            A[j]/=2;
        }
    }
    vector<int> c;
    LL rk=linear_equation(AA,b,c);
    LL ans;
    if(rk>=0){
        ans=modpow(2,N-rk,MOD);
    }else{
        ans=0;
    }

    //output
    cout << ans << endl;
    system("pause");
    return 0;
}

Submission Info

Submission Time
Task F - Limited Xor Subset
User moricup
Language C++ (GCC 9.2.1)
Score 500
Code Size 3930 Byte
Status
Exec Time 47 ms
Memory 5220 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:158:11: warning: ignoring return value of ‘int system(const char*)’, declared with attribute warn_unused_result [-Wunused-result]
  158 |     system("pause");
      |     ~~~~~~^~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
× 3
× 33
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_1.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_2.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_29.txt, subtask_1_3.txt, subtask_1_30.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt
Case Name Status Exec Time Memory
sample_01.txt 9 ms 4492 KB
sample_02.txt 5 ms 4484 KB
sample_03.txt 5 ms 4372 KB
subtask_1_1.txt 6 ms 4496 KB
subtask_1_10.txt 4 ms 4452 KB
subtask_1_11.txt 4 ms 4456 KB
subtask_1_12.txt 4 ms 4456 KB
subtask_1_13.txt 5 ms 4460 KB
subtask_1_14.txt 11 ms 4384 KB
subtask_1_15.txt 4 ms 4500 KB
subtask_1_16.txt 5 ms 4480 KB
subtask_1_17.txt 4 ms 4464 KB
subtask_1_18.txt 30 ms 5032 KB
subtask_1_19.txt 17 ms 4708 KB
subtask_1_2.txt 5 ms 4476 KB
subtask_1_20.txt 4 ms 4468 KB
subtask_1_21.txt 4 ms 4468 KB
subtask_1_22.txt 5 ms 4440 KB
subtask_1_23.txt 4 ms 4452 KB
subtask_1_24.txt 4 ms 4464 KB
subtask_1_25.txt 47 ms 5220 KB
subtask_1_26.txt 6 ms 4444 KB
subtask_1_27.txt 4 ms 4460 KB
subtask_1_28.txt 6 ms 4476 KB
subtask_1_29.txt 5 ms 4440 KB
subtask_1_3.txt 4 ms 4460 KB
subtask_1_30.txt 6 ms 4456 KB
subtask_1_4.txt 4 ms 4368 KB
subtask_1_5.txt 5 ms 4476 KB
subtask_1_6.txt 17 ms 4752 KB
subtask_1_7.txt 10 ms 4616 KB
subtask_1_8.txt 7 ms 4496 KB
subtask_1_9.txt 4 ms 4448 KB