結果

問題 No.2159 Filling 4x4 array
ユーザー hotman78hotman78
提出日時 2022-12-02 15:28:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,738 ms / 5,000 ms
コード長 1,708 bytes
コンパイル時間 2,532 ms
コンパイル使用メモリ 202,440 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 23:09:47
合計ジャッジ時間 80,067 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,702 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1,710 ms
6,940 KB
testcase_03 AC 1,696 ms
6,944 KB
testcase_04 AC 1,722 ms
6,944 KB
testcase_05 AC 1,733 ms
6,940 KB
testcase_06 AC 1,711 ms
6,940 KB
testcase_07 AC 1,697 ms
6,940 KB
testcase_08 AC 1,695 ms
6,944 KB
testcase_09 AC 1,720 ms
6,940 KB
testcase_10 AC 1,718 ms
6,940 KB
testcase_11 AC 1,722 ms
6,940 KB
testcase_12 AC 1,713 ms
6,944 KB
testcase_13 AC 1,733 ms
6,940 KB
testcase_14 AC 1,712 ms
6,944 KB
testcase_15 AC 1,723 ms
6,948 KB
testcase_16 AC 1,723 ms
6,940 KB
testcase_17 AC 1,701 ms
6,944 KB
testcase_18 AC 1,706 ms
6,944 KB
testcase_19 AC 1,707 ms
6,944 KB
testcase_20 AC 1,699 ms
6,940 KB
testcase_21 AC 1,701 ms
6,944 KB
testcase_22 AC 1,705 ms
6,940 KB
testcase_23 AC 1,712 ms
6,940 KB
testcase_24 AC 1,706 ms
6,944 KB
testcase_25 AC 1,689 ms
6,940 KB
testcase_26 AC 1,701 ms
6,940 KB
testcase_27 AC 1,696 ms
6,940 KB
testcase_28 AC 1,704 ms
6,940 KB
testcase_29 AC 1,700 ms
6,944 KB
testcase_30 AC 1,707 ms
6,944 KB
testcase_31 AC 1,738 ms
6,944 KB
testcase_32 AC 1,697 ms
6,944 KB
testcase_33 AC 1,728 ms
6,940 KB
testcase_34 AC 1,692 ms
6,940 KB
testcase_35 AC 1,705 ms
6,940 KB
testcase_36 AC 1,697 ms
6,944 KB
testcase_37 AC 1,706 ms
6,940 KB
testcase_38 AC 1,702 ms
6,944 KB
testcase_39 AC 1,709 ms
6,940 KB
testcase_40 AC 1,705 ms
6,940 KB
testcase_41 AC 1,720 ms
6,940 KB
testcase_42 AC 1,708 ms
6,940 KB
testcase_43 AC 1,686 ms
6,940 KB
testcase_44 AC 1,695 ms
6,944 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 1 ms
6,940 KB
testcase_49 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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<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;
}
0