結果
| 問題 |
No.663 セルオートマトンの逆操作
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-18 15:15:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,140 bytes |
| コンパイル時間 | 2,036 ms |
| コンパイル使用メモリ | 196,960 KB |
| 最終ジャッジ日時 | 2025-01-18 22:16:27 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 |
ソースコード
#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;
}