結果

問題 No.663 セルオートマトンの逆操作
ユーザー ミドリムシミドリムシ
提出日時 2018-03-09 22:48:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,234 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 73,076 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 13:49:26
合計ジャッジ時間 1,447 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 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}}};

int dp[2000][2][2][2][2];

int 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 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) << endl;
    ;
}
0