結果

問題 No.663 セルオートマトンの逆操作
ユーザー Asdf_QwertyZAsdf_QwertyZ
提出日時 2018-11-13 19:50:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,382 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 32,752 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-26 00:51:23
合計ジャッジ時間 1,854 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

constexpr int MAX_N = 2000, mod = 1000000007;

int N;
int e[MAX_N];
int dp[MAX_N+10][2][2][2][2];

int main()
{
  scanf( "%d", &N );
  rep( i, N )
    scanf( "%d", e+i );

  if( !e[0] )
    dp[0][0][0][0][0] = dp[0][0][0][1][0] = dp[0][1][1][1][1] = 1;
  else
    dp[0][0][1][0][0] = dp[0][0][1][1][0] = dp[0][1][0][0][1] = dp[0][1][0][1][1] = dp[0][1][1][0][1] = 1;

  rep( i, N-1 ) rep( k, 2 ) rep( l, 2 )
  {
    if( !e[i+1] )
    {
      dp[i+1][0][0][k][l] += dp[i][0][0][k][l];
      dp[i+1][0][0][k][l] %= mod;
      dp[i+1][0][0][k][l] += dp[i][1][0][k][l];
      dp[i+1][0][0][k][l] %= mod;
      dp[i+1][1][1][k][l] += dp[i][1][1][k][l];
      dp[i+1][1][1][k][l] %= mod;
    }
    else
    {
      dp[i+1][0][1][k][l] += dp[i][0][0][k][l];
      dp[i+1][0][1][k][l] %= mod;
      dp[i+1][0][1][k][l] += dp[i][1][0][k][l];
      dp[i+1][0][1][k][l] %= mod;
      dp[i+1][1][0][k][l] += dp[i][0][1][k][l];
      dp[i+1][1][0][k][l] %= mod;
      dp[i+1][1][1][k][l] += dp[i][0][1][k][l];
      dp[i+1][1][1][k][l] %= mod;
      dp[i+1][1][0][k][l] += dp[i][1][1][k][l];
      dp[i+1][1][0][k][l] %= mod;
    }
  }

  int ans = 0;

  rep( j, 2 ) rep( k, 2 )
    ans = (ans + dp[N-1][k][j][k][j]) % mod;

  printf( "%d\n", ans );

  return 0;
}
0