Pagini recente » Cod sursa (job #1980408) | Cod sursa (job #748472) | Cod sursa (job #1891910) | Cod sursa (job #2139194) | Cod sursa (job #826008)
Cod sursa(job #826008)
#include <cstdio>
using namespace std;
const int maxn = 10011;
short v[maxn];
int l;
int b(int poz);
int c(int poz);
int b(int poz)
{
if(poz>l)
return -1;
if(v[poz] == 2)
return b(poz+1);
if(v[poz] == 1 && v[poz+2] == 3)
return c(poz+4);
return -1;
}
int c(int poz)
{
if(poz>l)
return -1;
if(v[poz]==2)
return poz+1;
if(v[poz]==1 && v[poz+1]==2)
return poz+3;
if(v[poz]==3)
return c(b(poz+1));
return -1;
}
int main(void)
{
int n;
int i;
bool ok;
freopen("perle.in","r",stdin);
freopen("perle.out","w",stdout);
setvbuf(stdin,NULL,_IOFBF,1024);
scanf("%d",&n);
while(n--)
{
scanf("%d",&l);
for(i=1;i<=l;++i)
scanf("%d",v+i);
if(l==1)
printf("1\n");
else
{
ok = 0;
if(b(1) == l+1)
ok = 1;
if(c(1) == l+1)
ok = 1;
printf("%d\n",ok);
}
}
return 0;
}