Pagini recente » Cod sursa (job #2671898) | Cod sursa (job #585533) | Cod sursa (job #2239628) | Cod sursa (job #1400519) | Cod sursa (job #1288678)
#include <fstream>
#include <cstring>
#define dvect 10001;
using namespace std;
ifstream fin("perle.in");
ofstream fout("perle.out");
int n,a[10001],i,j,l,k;
int B(int x);
int C(int x);
int B(int x)
{
if(a[x]==2)
return B(x+1);
if(a[x]==1&&a[x+2]==3)
return C(x+4);
return 0;
}
int C(int x)
{
if(a[x]==2)
return x+1;
if(a[x]==3)
return C(B(x+1));
if(a[x]==1&&a[x+1]==2)
return x+3;
}
int main()
{
fin>>n;
for(i=1;i<=n;i++){
fin>>l;
for(j=1;j<=l;j++)
fin>>a[j];
if(l==1||B(1)==l+1||C(1)==l+1)
fout<<1<<"\n";
else
fout<<0<<"\n";
}
return 0;
}