結果

問題 No.663 セルオートマトンの逆操作
ユーザー ngtkanangtkana
提出日時 2020-04-04 11:43:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 2,517 ms
コンパイル使用メモリ 214,892 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 05:32:49
合計ジャッジ時間 3,951 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    std::vector<std::vector<lint>>zero(4,std::vector<lint>(4));
    lint mod=1'000'000'007;
    auto encode=[&](auto&&s){return (s.at(0)-'0')*2+(s.at(1)-'0');};
    auto mul=[&](auto&&a,auto&&b){
        auto c=zero;
        for(lint i=0;i<4;i++){
        for(lint j=0;j<4;j++){
        for(lint k=0;k<4;k++){
            c.at(i).at(j)+=a.at(i).at(k)*b.at(k).at(j);
            c.at(i).at(j)%=mod;
        }}}
        return c;
    };
    std::vector<std::vector<std::string>>members{{"000","100","111"},{"001","010","011","101","110"}};
    std::vector<std::vector<std::vector<lint>>>a(2,zero);
    for(lint i=0;i<2;i++){
        for(std::string s:members.at(i)){
            lint j=encode(s.substr(0,2));
            lint k=encode(s.substr(1,2));
            a.at(i).at(j).at(k)++;
        }
    }
    auto dp=zero;
    for(lint i=0;i<4;i++)dp.at(i).at(i)=1;
    lint n;std::cin>>n;
    while(n--){
        lint x;std::cin>>x;
        dp=mul(dp,a.at(x));
    }
    lint ans=0;
    for(lint i=0;i<4;i++)ans+=dp.at(i).at(i);
    ans%=mod;
    std::cout<<ans<<'\n';
}
0