結果

問題 No.663 セルオートマトンの逆操作
ユーザー face4face4
提出日時 2019-10-09 12:18:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,187 bytes
コンパイル時間 610 ms
コンパイル使用メモリ 70,064 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 23:30:48
合計ジャッジ時間 2,121 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cstring>
using namespace std;

int automaton(int i, int j, int k){
    if(j+k == 0 || i+j+k == 3)  return 0;
    return 1;
}

const int mod = 1000000007;
int dp[2000][2][2];
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];
    ll ans = 0;
    for(int s = 0; s < 1<<3; s++){
        memset(dp, 0, sizeof(dp));
        if(automaton(s&1, (s>>1)&1, (s>>2)&1) != v[0])    continue;
        dp[1][(s>>1)&1][(s>>2)&1]++;
        for(int i = 1; i+1 < n; i++){
            for(int j = 0; j < 2; j++){
                for(int k = 0; k < 2; k++){
                    for(int l = 0; l < 2; l++){
                       if(automaton(j, k, l) == v[i]){
                           dp[i+1][k][l] += dp[i][j][k];
                           dp[i+1][k][l] %= mod;
                       } 
                    }
                }
            }
        }
        for(int j = 0; j < 2; j++){
            if(automaton(j, s&1, (s>>1)&1) == v[n-1]){
                ans += dp[n-1][j][s&1];
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0