Cod sursa(job #2498889)

Utilizator david.teacaDavid Stefan Teaca david.teaca Data 24 noiembrie 2019 19:00:18
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>

typedef long long ll;

ll n, l, i, j;

ll list[10001];

ll ifB(ll pos), ifC(ll pos);

int main()

{

    freopen("perle.in", "r", stdin);

    freopen("perle.out", "w", stdout);

    scanf("%lld", &n);

    while(n--){

        scanf("%lld", &l);

        for(i=1; i<=l; ++i) scanf("%lld", &list[i]);

        if(l==1) printf("1\n");

        else{

            if(ifB(1)==l+1 || ifC(1)==l+1) printf("1\n");

            else printf("0\n");

        }

    }

    fclose(stdin);

    fclose(stdout);

    return 0;

}

ll ifB(ll pos){

    if(list[pos]==2) return ifB(pos+1);

    if(list[pos]==1 && list[pos+2]==3) return ifC(pos+4);

    return -1LL;

}

ll ifC(ll pos){

    if(list[pos]==2) return pos+1;

    if(list[pos]==3) return ifC(ifB(pos+1));

    if(list[pos]==1 && list[pos+1]==2) return pos+3;

}