結果

問題 No.2907 Business Revealing Dora Tiles
ユーザー 👑 獅子座じゃない人獅子座じゃない人
提出日時 2024-05-30 10:15:43
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 3,284 bytes
コンパイル時間 11,451 ms
コンパイル使用メモリ 254,488 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-09-23 10:48:41
合計ジャッジ時間 21,970 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 TLE * 1 -- * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/modint>
using namespace atcoder;
using mint=modint998244353;

unsigned long long nim_product(unsigned long long a, unsigned long long b, int d=6) {
    if(a==0 || b==0){
        return 0;
    }
    if(a==1){
        return b;
    }
    if(b==1){
        return a;
    }
    --d;
    unsigned long long p=1<<d;
    unsigned long long a_h=a>>p;
    unsigned long long a_l=a-(a_h<<p);
    unsigned long long b_h=b>>p;
    unsigned long long b_l=b-(b_h<<p);
    unsigned long long al_bl=nim_product(a_l, b_l, d);
    unsigned long long ahl_bhl=nim_product(a_h^a_l, b_h^b_l, d);
    unsigned long long ah_bh=nim_product(a_h, b_h, d);
    unsigned long long ah_bh_h=nim_product(ah_bh, 1<<(p-1), d);
    return ((al_bl^ahl_bhl)<<p)^(al_bl^ah_bh_h);
}

unsigned long long nim_inv(unsigned long long a) {
    unsigned long long e=18446744073709551614ULL;
    unsigned long long p=1;
    while(e>0){
        if(e%2>0){
            p=nim_product(p, a);
        }
        a=nim_product(a, a);
        e/=2;
    }
    return p;
}

int gauss(int r, int c, vector<vector<unsigned long long>> & m) {
    int rank=0;
    for(int i=0;i<c;++i){
        int pivot=-1;
        for(int j=rank;j<r;++j){
            if(m[j][i]>0){
                pivot=j;
                break;
            }
        }
        if(pivot==-1){
            continue;
        }
        swap(m[pivot], m[rank]);
        auto inv=nim_inv(m[rank][i]);
        m[rank][i]=1;
        for(int k=rank+1;k<c;++k){
            m[rank][k]=nim_product(m[rank][k], inv);
        }
        for(int j=rank+1;j<r;++j){
            auto factor=m[j][i];
            m[j][i]=0;
            for(int k=rank+1;k<c;++k){
                m[j][k]^=nim_product(m[rank][k], factor);
            }
        }
        ++rank;
        if(rank==r){
            break;
        }
    }
    return rank;
}

int main(void)
{
    int n,t;
    cin >> n >> t;
    vector h(t, vector<unsigned long long>(n));
    for(int i=0;i<t;++i){
        for(int j=0;j<n;++j){
            cin >> h[i][j];
            --h[i][j];
        }
    }
    mint ans=0;
    for(unsigned int s=0;s<(unsigned int)(1<<n);++s){
        int count=popcount(s);
        if(count==0){
            if(n%2>0){
                --ans;
            } else {
                ++ans;
            }
            continue;
        }
        if(count==1){
            if(n%2>0){
                ++ans;
            } else {
                --ans;
            }
            continue;
        }
        vector m(t, vector<unsigned long long>(count));
        int cur=0;
        for(int j=0;j<n;++j){
            if((s&(1<<j))>0){
                for(int i=0;i<t;++i){
                    m[i][cur]=h[i][j];
                }
                ++cur;
            }
        }
        int rank=gauss(t, count, m);
        if(n%2>0){
            if(count%2>0){
                ans+=mint(2).pow(64).pow(count-rank);
            } else {
                ans-=mint(2).pow(64).pow(count-rank);
            }
        } else {
            if(count%2>0){
                ans-=mint(2).pow(64).pow(count-rank);
            } else {
                ans+=mint(2).pow(64).pow(count-rank);
            }
        }
    }
    cout << ans.val() << endl;
    return 0;
}
0