Submission #24934987


Source Code Expand

#include <iostream>
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
const long long MOD = 998244353;

// BitMatrix
const int MAX_ROW = 610; // to be set
const int MAX_COL = 610; // to be set
struct BitMatrix {
    int n, m;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int n_ = 1, int m_ = 1) {n = n_; m = m_;}
    inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
    inline friend ostream& operator << (ostream& s, BitMatrix M) {
        s << endl;
        for (int i = 0; i < M.n; ++i) {
            for (int j = 0; j < M.m; ++j) s << M.val[i][j];
            s << endl;
        }
        return s;
    }
};

inline BitMatrix operator * (BitMatrix A, BitMatrix B) {
    BitMatrix R(A.n, B.m);
    BitMatrix tB(B.m, B.n);
    for (int i = 0; i < tB.n; ++i) for (int j = 0; j < tB.m; ++j) tB[i][j] = B[j][i];
    for (int i = 0; i < R.n; ++i) for (int j = 0; j < R.m; ++j) R[i][j] = (A[i] & tB[j]).any();
    return R;
}

int linear_equation(BitMatrix A, vector<int> b) {
    int rank = 0;
    for (int i = 0; i < A.n; ++i) { A[i][A.m] = b[i]; }

    for (int i = 0; i < A.m; ++i) {
        int pivot = -1;
        for (int j = rank; j < A.n; ++j) {
            if (A[j][i]) {
                pivot = j;
                break;
            }
        }
        if (pivot != -1) {
            swap(A[pivot], A[rank]);
            for (int j = 0; j < A.n; ++j) if (j != rank && A[j][i]) A[j] ^= A[rank];
            ++rank;
        }
    }

    for (int i = rank; i < A.n; ++i) if (A[i][A.m]) return -1; // 解なし   
    return rank;
};

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() { 
    int N, M; cin >> N >> M;
    BitMatrix A(M, N);
    for (int i = 0; i < N; ++i) {
      	int k; cin >> k;
        for (int j = 0; j < k; ++j) {
            int a; cin >> a; a--;
            A[a][i] = 1;
        }
    }
  	vector<int> S(M); for(int i = 0; i < M; i++)cin >> S[i];
    vector<int> res;
    int r = linear_equation(A, S); 
 	if(r == -1)cout << 0 << endl;
    else cout << (modpow(2LL, N - r, MOD) + MOD) % MOD << endl;
}

Submission Info

Submission Time
Task 057 - Flip Flap(★6)
User Example
Language C++ (GCC 9.2.1)
Score 6
Code Size 2325 Byte
Status AC
Exec Time 21 ms
Memory 3688 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 4
AC × 38
Set Name Test Cases
Sample Sample_1.txt, Sample_2.txt, Sample_3.txt, Sample_4.txt
All Hand_1.txt, Hand_2.txt, Hand_3.txt, Hand_4.txt, Hand_5.txt, Hand_6.txt, Max_Random_1.txt, Max_Random_2.txt, Max_Random_3.txt, Max_Random_4.txt, Max_Random_5.txt, Max_Random_6.txt, Max_Random_7.txt, Max_Random_8.txt, Random_01.txt, Random_02.txt, Random_03.txt, Random_04.txt, Random_05.txt, Random_06.txt, Random_07.txt, Random_08.txt, Random_09.txt, Random_10.txt, Random_11.txt, Random_12.txt, Random_13.txt, Random_14.txt, Random_15.txt, Random_16.txt, Random_17.txt, Random_18.txt, Random_19.txt, Random_20.txt, Sample_1.txt, Sample_2.txt, Sample_3.txt, Sample_4.txt
Case Name Status Exec Time Memory
Hand_1.txt AC 5 ms 3496 KiB
Hand_2.txt AC 21 ms 3512 KiB
Hand_3.txt AC 2 ms 3524 KiB
Hand_4.txt AC 17 ms 3688 KiB
Hand_5.txt AC 16 ms 3636 KiB
Hand_6.txt AC 2 ms 3516 KiB
Max_Random_1.txt AC 16 ms 3456 KiB
Max_Random_2.txt AC 16 ms 3528 KiB
Max_Random_3.txt AC 14 ms 3512 KiB
Max_Random_4.txt AC 14 ms 3584 KiB
Max_Random_5.txt AC 16 ms 3508 KiB
Max_Random_6.txt AC 15 ms 3512 KiB
Max_Random_7.txt AC 14 ms 3584 KiB
Max_Random_8.txt AC 17 ms 3644 KiB
Random_01.txt AC 2 ms 3600 KiB
Random_02.txt AC 2 ms 3528 KiB
Random_03.txt AC 3 ms 3460 KiB
Random_04.txt AC 2 ms 3640 KiB
Random_05.txt AC 12 ms 3612 KiB
Random_06.txt AC 7 ms 3636 KiB
Random_07.txt AC 12 ms 3444 KiB
Random_08.txt AC 8 ms 3652 KiB
Random_09.txt AC 2 ms 3452 KiB
Random_10.txt AC 2 ms 3684 KiB
Random_11.txt AC 13 ms 3480 KiB
Random_12.txt AC 2 ms 3604 KiB
Random_13.txt AC 2 ms 3504 KiB
Random_14.txt AC 3 ms 3504 KiB
Random_15.txt AC 3 ms 3452 KiB
Random_16.txt AC 3 ms 3528 KiB
Random_17.txt AC 9 ms 3656 KiB
Random_18.txt AC 3 ms 3608 KiB
Random_19.txt AC 4 ms 3608 KiB
Random_20.txt AC 12 ms 3652 KiB
Sample_1.txt AC 2 ms 3456 KiB
Sample_2.txt AC 2 ms 3576 KiB
Sample_3.txt AC 2 ms 3648 KiB
Sample_4.txt AC 2 ms 3652 KiB