結果
| 問題 | No.663 セルオートマトンの逆操作 | 
| コンテスト | |
| ユーザー |  dnish | 
| 提出日時 | 2018-06-20 18:12:03 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,410 bytes | 
| コンパイル時間 | 1,509 ms | 
| コンパイル使用メモリ | 168,032 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-30 17:26:22 | 
| 合計ジャッジ時間 | 2,430 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 29 | 
ソースコード
#include "bits/stdc++.h"
#define REP(i,n,N) for(ll i=(n); i<(N); i++)
#define RREP(i,n,N) for(ll i=(N-1); i>=n; i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define p(s) cout<<(s)<<endl
#define p2(a,b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
ll N;
ll e[2010];
ll dp[2010][2][2];
ll check(ll a,ll b, ll c){
    if(b==0&&c==0) return 0;
    if(a==1&&b==1&&c==1) return 0;
    return 1;
}
int main() {
    cin >> N;
    REP(i, 0, N) cin >> e[i];
    ll ans=0;
    REP(w1, 0, 2) {
        REP(w2, 0, 2) {
            REP(k,0,N+1) REP(a,0,2) REP(b,0,2) dp[k][a][b]=0;
            dp[2][w1][w2]=1;
            REP(l,2,N){
                REP(i,0,2){
                    REP(j,0,2){
                        REP(k,0,2){
                            if (check(i, j, k) == e[l-1]) {
                                dp[l+1][j][k] += dp[l][i][j];
                                dp[l+1][j][k] %= mod;
                            }
                        }
                    }
                }
            }
            REP(i,0,2){
                REP(j,0,2){
                    if(check(i,j,w1)==e[N-1]&&check(j,w1,w2)==e[0]){
                        ans+=dp[N][i][j];
                        ans%=mod;
                    }
                }
            }
        }
    }
    p(ans);
    return 0;
}
            
            
            
        