Pagini recente » Cod sursa (job #758856) | Cod sursa (job #2335932) | Cod sursa (job #2971471) | Cod sursa (job #1452302) | Cod sursa (job #2435951)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("perle.in");
ofstream out("perle.out");
int n, l, a[10005];
int c(int t);
int b(int t)
{
if(a[t]==2) return b(t+1);
if(a[t]==1 && a[t+2]==3) return c(t+4);
return 0;
}
int c(int t)
{
if(a[t]==2) return t+1;
if(a[t]==3) return c(b(t+1));
if(a[t]==1 && a[t+1]==2) return t+3;
return 0;
}
int main()
{
in>>n;
for(int i=1;i<=n;i++)
{
in>>l;
for(int j=1;j<=l;j++)
{
in>>a[j];
}
if(l==1)
out<<1;
else if(l==3 || (l>6 && a[1]==3))if(c(1)==l+1)out<<1;else out<<0;
else if((a[1]==2 && l>5) || (a[1]==1 && l>4))if(b(1)==l+1)out<<1;else out<<0;
else out<<0;
out<<'\n';
}
return 0;
}