結果
| 問題 |
No.663 セルオートマトンの逆操作
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-04 11:43:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,280 bytes |
| コンパイル時間 | 2,142 ms |
| コンパイル使用メモリ | 208,120 KB |
| 最終ジャッジ日時 | 2025-01-09 14:00:19 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 |
ソースコード
#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';
}
ngtkana