Cod sursa(job #695045)

Utilizator Coman95coman cosmin Coman95 Data 28 februarie 2012 10:09:29
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<fstream>
#define dim 100005
using namespace std;

int x[dim],n;
int b(int p);int c(int p);
int b(int p)
{
	if(p>=n+1)
		return -1;
	if(x[p]==2)
		return b(p+1);
	if(x[p]==1 && x[p+2]==3)
		return c(p+4);
	return -1;
}
int c(int p)
{
	if(x[p]==2)
		return p+1;
	if(x[p]==1 && x[p+1]==2)
		return p+3;
	if(x[p]==3)
		return c(b(p+1));
	return -1;
}
int main()
{
	ifstream fin("perle.in");
	ofstream fout("perle.out");
	int t;
	fin >> t;
	for(;t;--t)
	{
		fin >> n;
		for(int i=1;i<=n;++i)
			fin >> x[i];
		int s=b(1);
		if(s!=n+1)
			s=c(1);
		if(n==1 || s==n+1)
		{
			fout << "1" << '\n';
			continue;
		}
		fout << "0" << '\n';
	}
	return 0;
}