結果

問題 No.663 セルオートマトンの逆操作
ユーザー ミドリムシミドリムシ
提出日時 2018-03-09 22:49:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,265 bytes
コンパイル時間 3,755 ms
コンパイル使用メモリ 72,892 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-31 13:41:50
合計ジャッジ時間 1,866 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

int N;
vector<int> nums;

const int conversion[2][2][2] = {{{0, 1}, {1, 1}}, {{0, 1}, {1, 0}}};

long dp[2000][2][2][2][2];

long choose(int now, int back_back, int back, int first, int second){
    if(now == N){
        return conversion[back_back][back][first] == nums[N - 1] && conversion[back][first][second] == nums[0];
    }else if(dp[now][back_back][back][first][second] != -1){
        return dp[now][back_back][back][first][second];
    }else{
        return dp[now][back_back][back][first][second] = (choose(now + 1, back, 0, first, second) * (conversion[back_back][back][0] == nums[now - 1]) +
                                                          choose(now + 1, back, 1, first, second) * (conversion[back_back][back][1] == nums[now - 1])) % int(1e9 + 7);
    }
}

int main(){
    cin >> N;
    nums.resize(N);
    for(int i = 0; i < N; i++){
        cin >> nums[i];
    }
    for(int i = 0; i < 2000; i++){
        for(int j = 0; j < 16; j++){
            dp[i][j & 1][(j >> 1) & 1][(j >> 2) & 1][(j >> 3) & 1] = -1;
        }
    }
    cout << (choose(2, 0, 0, 0, 0) + choose(2, 0, 1, 0, 1) + choose(2, 1, 0, 1, 0) + choose(2, 1, 1, 1, 1)) % int(1e9 + 7) << endl;
}
0