結果
| 問題 | 
                            No.2159 Filling 4x4 array
                             | 
                    
| コンテスト | |
| ユーザー | 
                             hotman78
                         | 
                    
| 提出日時 | 2022-12-02 15:28:03 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,990 ms / 5,000 ms | 
| コード長 | 1,708 bytes | 
| コンパイル時間 | 2,175 ms | 
| コンパイル使用メモリ | 199,604 KB | 
| 最終ジャッジ日時 | 2025-02-09 03:11:17 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 45 | 
ソースコード
#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
using lint=long long;
using mint=atcoder::static_modint<998244353>;
#define rep(i,n) for(int i=0;i<int(n);++i)
int main(){
    array<lint,8> v;
    rep(i,8)cin>>v[i];
    rep(i,8)v[i]-=4;
    if(v[0]+v[1]+v[2]+v[3]!=v[4]+v[5]+v[6]+v[7]){
        cout<<0<<endl;
        return 0;
    }
    swap(v[3],v[6]);
    swap(v[6],v[7]);
    vector<vector<mint>> dp(31,vector<mint>(1<<14));
    dp[0][0]=1;
    array<lint,(1<<9)>a;
    a.fill(0);
    rep(i,1<<9){
        rep(j,3)rep(k,3){
            if(i>>(j*3+k)&1){
                a[i]+=1<<(j*2);
                a[i]+=1<<((k+3)*2);
            }
        }
    }
    array<lint,30>v2;
    v2.fill(0);
    rep(d,30){
        rep(j,7){
            v2[d]+=(v[j]>>d&1)<<(j*2);
        }
    }
    rep(d,30){
        //flag : 解説におけるh',w' を2bitずつに割り当てたもの
        rep(flag,1<<14){
            rep(i,1<<9){
                // 前半3制約の内遇奇が合わない物
                const lint tmp=((flag^a[i]^v2[d])&21LL);
                // 7つ目の制約の変化量
                const lint cnt=__builtin_popcountll(tmp);
                // 遷移の値を加算したもの
                assert(cnt<4);
                const lint tmp2=(flag+a[i]+(cnt<<12))+(((flag^(a[i]+(cnt<<12)))^v2[d])&5461LL)-v2[d];
                assert(v2[d]==(v2[d]&5461LL));
                // 竹DPの更新後の値
                assert(tmp2>=0);
                assert(tmp2%2==0);
                const lint tmp3=tmp2/2;
                assert(tmp3<(1LL<<14));
                dp[d+1][tmp3]+=dp[d][flag];
            }
        }
    }
    cout<<dp[30][0].val()<<endl;
}
            
            
            
        
            
hotman78