Pagini recente » Cod sursa (job #1078423) | Cod sursa (job #1451102) | Cod sursa (job #2965887) | Cod sursa (job #2803327) | Cod sursa (job #333908)
Cod sursa(job #333908)
#include<cstdio>
const int N = (1<<14);
int n;
short int s[N];
int c(int);
int b(int poz)
{
if(poz>n-5)
return 0;
if(s[poz]==2)
return b(poz+1);
if(s[poz]==1 && s[poz+2]==3)
return c(poz+4);
return 0;
}
int c(int poz)
{
if(s[poz]==2)
return poz+1;
if(s[poz]==1 && s[poz+1]==2)
return poz+3;
if(s[poz]==3)
return c(b(poz+1));
return 0;
}
int rez()
{
if(n==1)
return 1;
if(b(1)==n+1 || c(1)==n+1)
return 1;
return 0;
}
int main()
{
freopen("perle.in","r",stdin);
freopen("perle.out","w",stdout);
int t,i;
scanf("%d",&t);
while(t--)
{
scanf("%d ",&n);
for(i=1;i<=n;++i)
scanf("%hd",&s[i]);
printf("%d\n",rez());
}
return 0;
}