Cod sursa(job #2928160)

Utilizator Robert_NicuNicu Robert Cristian Robert_Nicu Data 22 octombrie 2022 12:03:23
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<bits/stdc++.h>
using namespace std;
ifstream fin("perle.in");
ofstream fout("perle.out");
int v[10001];
int i, n, m;

int B(int poz);
int C(int poz);

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

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

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