結果
| 問題 |
No.663 セルオートマトンの逆操作
|
| コンテスト | |
| ユーザー |
horiesiniti
|
| 提出日時 | 2017-10-14 05:05:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,614 bytes |
| コンパイル時間 | 1,578 ms |
| コンパイル使用メモリ | 55,744 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 13:25:43 |
| 合計ジャッジ時間 | 1,565 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:35:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
35 | scanf("%d",&as[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<string.h>
#include<iostream>
long long int MOD=1000000007;
const int LIMIT=2004;
long long int dp[2][2][2][2];
long long int nextdp[2][2][2][2];
//dp[R][L][old][now]
//next[R][L][now][next]
int as[LIMIT];
int f(int a,int b,int c){
if((a==0)&&(b==0)&&(c==1)){
return 1;
}
if((a==0)&&(b==1)&&(c==0)){
return 1;
}
if((a==0)&&(b==1)&&(c==1)){
return 1;
}
if((a==1)&&(b==0)&&(c==1)){
return 1;
}
if((a==1)&&(b==1)&&(c==0)){
return 1;
}
return 0;
}
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&as[i]);
}
memset(dp,0,sizeof(dp));
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
if(f(i,j,k)==as[0]){
dp[i][j][j][k]=1;
}
}
}
}
long long int ans=0;
for(int c=1;c<n;c++){
memset(nextdp,0,sizeof(nextdp));
for(int r=0;r<2;r++){
for(int l=0;l<2;l++){
for(int old=0;old<2;old++){
for(int now=0;now<2;now++){
int b1=as[c];
if(c==n-2){
int b=f(old,now,r);
if(b==b1){
nextdp[r][l][now][r]=(nextdp[r][l][now][r]+dp[r][l][old][now])%MOD;
}
}else if(c==n-1){
if(r!=now)continue;
int b=f(old,r,l);
if(b==b1){
ans=(ans+dp[r][l][old][now])%MOD;
}
}else{
int b=f(old,now,0);
if(b==b1){
nextdp[r][l][now][0]=(nextdp[r][l][now][0]+dp[r][l][old][now])%MOD;
}
b=f(old,now,1);
if(b==b1){
nextdp[r][l][now][1]=(nextdp[r][l][now][1]+dp[r][l][old][now])%MOD;
}
}
}
}
}
}
memcpy(dp,nextdp,sizeof(nextdp));
}
std::cout<<ans<<"\n";
}
horiesiniti