Pagini recente » Cod sursa (job #2489093) | Cod sursa (job #890007) | Cod sursa (job #2945884) | Cod sursa (job #2714367) | Cod sursa (job #20359)
Cod sursa(job #20359)
#include <stdio.h>
int a[10001],n,i,t,max;
int presumec(int x,int lvl);
int presumeb(int x,int lvl)
{
//if (x>max) max=x;
if (x>n) return 0;
if (a[x]==2) return presumeb(x+1,lvl+1);
if (a[x]==1 && a[x+2]==3 && x+4<=n) return presumec(x+4,lvl+1);
return 0;
}
int presumec(int x,int lvl)
{
int r;
//if (x>max) max=x;
if (x>n) return 0;
if (a[x]==1 && a[x+1]==2 && x+1<=n) return x+3;
if (a[x]==3)
{
r=presumeb(x+1,lvl+1);
if (r!=0) return presumec(r+1,lvl+1); else return 0;
}
if (a[x]==2 && lvl>1) return x+1;
if (lvl==1 && a[x]==2 && n==1) return x+1;
return 0;
}
int main()
{
freopen("perle.in","r",stdin);
freopen("perle.out","w",stdout);
scanf("%d",&t);
for (;t>0;--t)
{
scanf("%d",&n);
for (i=1;i<=n;++i) scanf("%d",&a[i]);
if (n==1) printf("1\n"); else
//max=0;
if (presumeb(1,1)!=0) printf("1\n"); else
if (presumec(1,1)!=0) printf("1\n");
else
printf("0\n");
}
return 0;
}