Cod sursa(job #2816032)

Utilizator biancalautaruBianca Lautaru biancalautaru Data 10 decembrie 2021 21:46:23
Problema Perle Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
using namespace std;
ifstream fin("perle.in");
ofstream fout("perle.out");
int t,n,i,v[10005];
bool a,b,c;

bool pb();
bool pc();

bool pa() {
    if (i==n)
        return 1;
    return 0;
}
bool pb() {
    if (i==n || v[i]==3)
        return 0;
    if (v[i]==1) {
        if (v[i+2]==3) {
            i+=4;
            return pc();
        }
        return 0;
    }
    i++;
    return pb();
}

bool pc() {
    if (i==n) {
        if (v[i]==2)
            return 1;
        return 0;
    }
    if (v[i]==2)
        return 0;
    if (v[i]==1) {
        if (v[i+1]==2)
            return 1;
        return 0;
    }
    i++;
    int b=pb();
    i++;
    return b || pc();
}

int main() {
    fin>>t;
    while (t--) {
        fin>>n;
        for (i=1;i<=n;i++)
            fin>>v[i];
        i=1;
        a=pa();
        i=1;
        b=pb();
        i=1;
        c=pc();
        fout<<(a || b || c)<<"\n";
    }
    return 0;
}