Submission #59670861


Source Code Expand

#include <bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using namespace atcoder;
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<ll,ll> P;
constexpr ll mod=998244353;
typedef modint1000000007 mi;

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

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 main(){
    int n,m;cin>>n>>m;
    BitMatrix mat(n,m);
    rep(i,n){
        int t;cin>>t;
        rep(j,t){
            int a;cin>>a;
            mat[i].flip(a-1);
        }
    }

    int rank=GaussJordan(mat);

    bitset<MAX_COL>s,t;
    int row=0;

    rep(i,m){
        int si;
        cin>>si;
        s[i]=si;
        
        if(s[i]!=t[i]){
            while(1){
                if(mat[row][i]^t[i]==s[i]){
                    t^=mat[row];
                    row++;
                    break;
                }
                else{
                    row++;
                    if(row>=n){
                        cout<<0<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<pow_mod(2,n-rank,998244353)<<endl;
}

Submission Info

Submission Time
Task 057 - Flip Flap(★6)
User Rho17
Language C++ 20 (gcc 12.2)
Score 6
Code Size 2016 Byte
Status AC
Exec Time 11 ms
Memory 3720 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:66:36: warning: suggest parentheses around comparison in operand of ‘^’ [-Wparentheses]
   66 |                 if(mat[row][i]^t[i]==s[i]){

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 1 ms 3592 KiB
Hand_2.txt AC 11 ms 3536 KiB
Hand_3.txt AC 1 ms 3524 KiB
Hand_4.txt AC 6 ms 3536 KiB
Hand_5.txt AC 6 ms 3508 KiB
Hand_6.txt AC 1 ms 3580 KiB
Max_Random_1.txt AC 6 ms 3576 KiB
Max_Random_2.txt AC 6 ms 3612 KiB
Max_Random_3.txt AC 6 ms 3532 KiB
Max_Random_4.txt AC 6 ms 3580 KiB
Max_Random_5.txt AC 7 ms 3720 KiB
Max_Random_6.txt AC 6 ms 3524 KiB
Max_Random_7.txt AC 7 ms 3664 KiB
Max_Random_8.txt AC 6 ms 3524 KiB
Random_01.txt AC 1 ms 3464 KiB
Random_02.txt AC 1 ms 3580 KiB
Random_03.txt AC 1 ms 3664 KiB
Random_04.txt AC 1 ms 3508 KiB
Random_05.txt AC 4 ms 3588 KiB
Random_06.txt AC 3 ms 3572 KiB
Random_07.txt AC 5 ms 3520 KiB
Random_08.txt AC 3 ms 3468 KiB
Random_09.txt AC 1 ms 3480 KiB
Random_10.txt AC 1 ms 3524 KiB
Random_11.txt AC 4 ms 3500 KiB
Random_12.txt AC 1 ms 3524 KiB
Random_13.txt AC 1 ms 3524 KiB
Random_14.txt AC 1 ms 3524 KiB
Random_15.txt AC 1 ms 3536 KiB
Random_16.txt AC 2 ms 3524 KiB
Random_17.txt AC 4 ms 3536 KiB
Random_18.txt AC 1 ms 3480 KiB
Random_19.txt AC 1 ms 3588 KiB
Random_20.txt AC 3 ms 3524 KiB
Sample_1.txt AC 1 ms 3468 KiB
Sample_2.txt AC 1 ms 3572 KiB
Sample_3.txt AC 1 ms 3716 KiB
Sample_4.txt AC 1 ms 3664 KiB