Cod sursa(job #2220067)

Utilizator Hidden.bdBurlacu Doru Hidden.bd Data 10 iulie 2018 14:24:31
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <string>
#include <queue>

const long double PI = acos(-1);

using namespace std;

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

//#define fin cin
//#define fout cout

int teste, lg;
int c[10002];
int poz;
int C(int &poz);
int B(int &poz){
    if( c[poz] == 2 ){
        poz++;
        return B(poz);
    }else if( c[poz] == 1 ){
        if( c[poz+2] == 3 ){
            poz += 4;
            return C(poz);
        }
    }
    return 0;
}

int C( int &poz ){
    if( c[poz] == 2 ){
        ++poz;
        return 1;
    }else if( c[poz] == 3 ){
        ++poz;
        if( B(poz) )
            return C(poz);
    }else if( c[poz] == 1 && c[poz+1] == 2 ){
        poz += 3;
        return 1;
    }
    return 0;
}
int main(){
    fin >> teste;
    for( int i = 1 ; i <= teste ; ++i ){
        fin >> lg;
        for(int j = 1 ; j <= lg ; ++j)
            fin >> c[j];
        if( lg == 1 ) fout << 1 << "\n";
        else{
            poz = 1;
            
            if( B(poz) && poz == lg + 1 )
                fout << 1 << "\n";
            else{
                poz = 1;
                
                if( C(poz) && poz == lg + 1 ) fout << 1 << "\n";
                else fout << 0 << "\n";
            }
        }
    }
    
    return 0;
}