Cod sursa(job #54612)

Utilizator Darth_NiculusIvan Nicolae Darth_Niculus Data 25 aprilie 2007 10:49:22
Problema Perle Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
/* Ivan Nicolae - Bucuresti */

#include <stdio.h>
#include <string.h>

#define NMAX 10001
#define _fin "perle.in"
#define _fout "perle.out"

int i,n,t,A[NMAX+10];

int estec(int);

int esteb(int x)
{
 if (x>n)
   return 0;
   else
 if (A[x]==2)
   return esteb(x+1);
   else
 if (A[x]==1 && A[x+2]==3)
   return estec(x+4);
 return 0;
}

int estec(int x)
{
 if (x>n)
   return 0;
   else
 if (A[x]==2)
   return x+1;
   else
 if (A[x]==3)
   {
    int ala=esteb(x+1);
    if (ala > 0)
      return estec(ala);
   }
  else
 if (A[x]==1 && A[x+1]==2)
   return x+3;
 return 0;
}

int main()
{
 freopen(_fin,"r",stdin);
 freopen(_fout,"w",stdout);

 scanf("%d",&t);
 for (int te=1;te<=t;te++)
    {
     scanf("%d",&n);
     for (i=1;i<=n;i++)
        scanf("%d",&A[i]);

     if (esteb(1)>=n) printf("1\n");
       else
     if (estec(1)>=n) printf("1\n");
       else
     if (n == 1) printf("1\n");
       else
     printf("0\n");
    }

 fclose(stdin);
 fclose(stdout);
 return 0;
}