Cod sursa(job #1875390)

Utilizator raluca1234Tudor Raluca raluca1234 Data 11 februarie 2017 00:57:29
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <cstdio>

#define maxN 10001

using namespace std;

int v[maxN+1];

int extendC(int pos);

int extendB(int pos){
    if (v[pos]==2)
        return extendB(pos+1);
    if (v[pos]==1 && v[pos+2]==3)
        return extendC(pos+4);
    return -1;
}

int extendC(int pos){
    if (v[pos]==2)
        return pos+1;
    if (v[pos]==3)
        return extendC(extendB(pos+1));
    if (v[pos]==1 && v[pos+1]==2)
        return pos+3;
    return -1;
}

int main(){
    freopen("perle.in", "r", stdin);
    freopen("perle.out", "w", stdout);
    int q, n, i;
    scanf("%d", &q);
    while (q--){
        scanf("%d", &n);
        for (i=1; i<=n; i++)
            scanf("%d", &v[i]);
        if (n==1)
            printf("1\n");
        else
            if (extendB(1)==n+1 || extendC(1)==n+1)
                printf("1\n");
            else printf("0\n");
    }
    return 0;
}