結果

問題 No.2159 Filling 4x4 array
ユーザー hotman78hotman78
提出日時 2022-12-02 17:32:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,441 ms / 5,000 ms
コード長 1,585 bytes
コンパイル時間 2,187 ms
コンパイル使用メモリ 204,436 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 23:14:13
合計ジャッジ時間 66,162 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,415 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1,441 ms
6,944 KB
testcase_03 AC 1,396 ms
6,940 KB
testcase_04 AC 1,428 ms
6,944 KB
testcase_05 AC 1,401 ms
6,940 KB
testcase_06 AC 1,387 ms
6,944 KB
testcase_07 AC 1,417 ms
6,944 KB
testcase_08 AC 1,387 ms
6,944 KB
testcase_09 AC 1,420 ms
6,940 KB
testcase_10 AC 1,399 ms
6,944 KB
testcase_11 AC 1,386 ms
6,940 KB
testcase_12 AC 1,415 ms
6,944 KB
testcase_13 AC 1,386 ms
6,940 KB
testcase_14 AC 1,378 ms
6,940 KB
testcase_15 AC 1,384 ms
6,940 KB
testcase_16 AC 1,398 ms
6,944 KB
testcase_17 AC 1,370 ms
6,944 KB
testcase_18 AC 1,377 ms
6,940 KB
testcase_19 AC 1,404 ms
6,940 KB
testcase_20 AC 1,390 ms
6,940 KB
testcase_21 AC 1,370 ms
6,940 KB
testcase_22 AC 1,371 ms
6,944 KB
testcase_23 AC 1,397 ms
6,940 KB
testcase_24 AC 1,415 ms
6,944 KB
testcase_25 AC 1,392 ms
6,940 KB
testcase_26 AC 1,372 ms
6,944 KB
testcase_27 AC 1,386 ms
6,944 KB
testcase_28 AC 1,384 ms
6,944 KB
testcase_29 AC 1,385 ms
6,940 KB
testcase_30 AC 1,408 ms
6,940 KB
testcase_31 AC 1,405 ms
6,940 KB
testcase_32 AC 1,401 ms
6,940 KB
testcase_33 AC 1,380 ms
6,944 KB
testcase_34 AC 1,389 ms
6,944 KB
testcase_35 AC 1,399 ms
6,940 KB
testcase_36 AC 1,402 ms
6,940 KB
testcase_37 AC 1,393 ms
6,944 KB
testcase_38 AC 1,375 ms
6,944 KB
testcase_39 AC 1,391 ms
6,940 KB
testcase_40 AC 1,385 ms
6,944 KB
testcase_41 AC 1,392 ms
6,940 KB
testcase_42 AC 1,397 ms
6,944 KB
testcase_43 AC 1,380 ms
6,944 KB
testcase_44 AC 1,395 ms
6,940 KB
testcase_45 AC 1 ms
6,944 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 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<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