Cod sursa(job #387337)

Utilizator cocoshilaClaudiu cocoshila Data 27 ianuarie 2010 13:09:13
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#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;
}