Cod sursa(job #2928170)

Utilizator AlexTimplaruAlexandru Timplaru AlexTimplaru Data 22 octombrie 2022 12:19:18
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
// https://www.infoarena.ro/problema/perle
#include <fstream>

using namespace std;

ifstream fin("perle.in");
ofstream fout("perle.out");

short v[10010];

int B(int p);
int C(int p);

int B(int p)
{
    if(v[p] == 2)
    {
        return B(p+1);
    }
    else if(v[p] == 1 && v[p+2] == 3 && v[p+4] != 0)
    {
        return C(p+4);
    }
    else return -1;
}

int C(int p)
{
    if(v[p] == 1 && v[p+1] == 2 && v[p+2] != 0)
    {
        return p+2;
    }
    else if(v[p] == 3)
    {
        int v = B(p+1);
        return C(v+1);
    }
    else if(v[p] == 2)
    {
        return p;
    }
    else return -1;
}


int main()
{
    int n;
    fin >> n;
    for(int i = 0; i < n; i++)
    {
        int x;
        fin >> x;
        for(int j = 0; j < x; j++)
        {
            fin >> v[j];
        }
        //fout << "B=" << B(0) << " C=" << C(0) << " ";
        if(x==1 || B(0) + 1 == x || C(0) + 1 == x)
            fout << "1\n";
        else
            fout <<"0\n";
    }
}