Cod sursa(job #547699)

Utilizator dadudadUdrea Dragos dadudad Data 6 martie 2011 17:25:55
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <stdio.h>

int a[10001],n,i,t,max;
int presumec(int x);
int presumeb(int x)
{
if (x>n) return 0;
if (a[x]==2) return presumeb(x+1);
if (a[x]==1 && a[x+2]==3 && x+4<=n) return presumec(x+4);
return 0;
}
 
int presumec(int x)
{
int r;
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);
if (r!=0) return presumec(r); else return 0;
}
if (a[x]==2) 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
if (presumeb(1)>=n) printf("1\n"); else
if (presumec(1)>=n) printf("1\n");
else       
printf("0\n");
}
return 0;
}