Cod sursa(job #2486345)

Utilizator CharacterMeCharacter Me CharacterMe Data 2 noiembrie 2019 18:41:30
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 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;
}