Pagini recente » Cod sursa (job #739170) | Cod sursa (job #1675003) | Cod sursa (job #2378751) | Cod sursa (job #628968) | Cod sursa (job #2220067)
#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;
}