結果

問題 No.2159 Filling 4x4 array
ユーザー hotman78
提出日時 2022-12-02 17:32:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,607 ms / 5,000 ms
コード長 1,585 bytes
コンパイル時間 1,987 ms
コンパイル使用メモリ 200,624 KB
最終ジャッジ日時 2025-02-09 03:14:42
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#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<int,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<int,(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<int,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){
            // 左上9マスの選び方
            rep(i,1<<9){
                // tmp : 前半3制約の内遇奇が合わない物
                // 21 = 1+4+4^2
                const int tmp=((flag^a[i]^v2[d])&21LL);
                // cnt : 7つ目の制約の変化bit
                const int cnt=__builtin_popcountll(tmp)<<12;
                // tmp2 : 遷移の値を加算したもの
                // 5461 = 1+4+...+4^16
                const int tmp2=(flag+a[i]+cnt)+(((flag^(a[i]+cnt))^v2[d])&5461LL)-v2[d];
                dp[d+1][tmp2/2]+=dp[d][flag];
            }
        }
    }
    cout<<dp[30][0].val()<<endl;
}
0