結果

問題 No.1870 Xor Matrix
ユーザー rogi52rogi52
提出日時 2022-03-11 22:12:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 3,428 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 199,400 KB
最終ジャッジ日時 2025-01-28 08:42:17
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const int MAX_ROW = 310;
const int MAX_COL = 310;
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 Gauss_Jordan(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;
}

// Ax = b
int Linear_Equation(BitMatrix A, vector<int> &x, vector<int> b) {
    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 = Gauss_Jordan(M, true);
    for(int row = rank; row < m; ++row) if(M[row][n]) return -1;
    x.assign(n, 0);
    for(int i = 0; i < rank; ++i) x[i] = M[i][n];
    return rank; // #(solution) = 2^{n - rank}
}

template< int mod >
struct Fp {
    int x;
    Fp() : x(0) {}
    Fp(int64_t y) : x(y >= 0 ? y % mod : (mod + y % mod) % mod) {}
    Fp &operator+=(const Fp &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    Fp &operator-=(const Fp &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
    Fp &operator*=(const Fp &p) { x = (int)(1LL * x * p.x % mod); return *this; }
    Fp &operator/=(const Fp &p) { *this *= p.inv(); return *this; }
    Fp operator-() const { return Fp(-x); }
    Fp operator+(const Fp &p) const { return Fp(*this) += p; }
    Fp operator-(const Fp &p) const { return Fp(*this) -= p; }
    Fp operator*(const Fp &p) const { return Fp(*this) *= p; }
    Fp operator/(const Fp &p) const { return Fp(*this) /= p; }
    bool operator==(const Fp &p) const { return x == p.x; }
    bool operator!=(const Fp &p) const { return x != p.x; }

    Fp inv() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return Fp(u);
    }

    Fp pow(int64_t n) const {
        Fp ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const Fp &p) { return os << p.x; }
    friend istream &operator>>(istream &is, Fp &a) {
        int64_t t;
        is >> t;
        a = Fp< mod > (t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = Fp<998244353>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,M; cin >> N >> M;
    vector<int> A(N), B(M);
    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i];

    mint ans = 1;
    mint p2 = mint(2).pow((N - 1) * (M - 1));
    rep(b,20) {
        int A_xor = 0, B_xor = 0;
        rep(i,N) A_xor ^= !!(A[i] & (1 << b));
        rep(i,M) B_xor ^= !!(B[i] & (1 << b));
        ans *= (A_xor == B_xor ? p2 : 0);
    }

    cout << ans << endl;
}
0