結果

問題 No.663 セルオートマトンの逆操作
ユーザー kk
提出日時 2021-02-18 15:15:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,140 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 201,740 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 23:28:33
合計ジャッジ時間 3,270 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1e9 + 7;

long long dp[2000][1<<3][1<<2];

bool check(int x, int mask) {
  if (mask == 7) return x == 0;
  if (!(mask & 3)) return x == 0;
  return x == 1;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  for (int mask = 0; mask < 1<<3; mask++) {
    if (check(a[1], mask))
        dp[0][mask][mask>>1] = 1;
  }

  for (int i = 1; i + 2 < n; i++) {
    for (int mask = 0; mask < 1<<3; mask++) {
      if (!check(a[i+1], mask)) continue;
      for (int j = 0; j < 1<<2; j++) {
        int n1 = mask >> 1;
        int n2 = n1 | (1 << 2);
        dp[i][mask][j] = (dp[i-1][n1][j] + dp[i-1][n2][j]) % MOD;
      }
    }
  }

  long long ret = 0;
  for (int mask = 0; mask < 1<<3; mask++) {
    for (int j = 0; j < 1<<2; j++) {
      int n1 = ((mask & 3) << 1) | (j >> 1);
      int n2 = ((mask & 1) << 2) | j;
      if (check(a[n-1], n1) && check(a[0], n2)) {
        ret += dp[n-3][mask][j];
        ret %= MOD;
      }
    }
  }
  cout << ret << endl;

  return 0;
}
0