Cod sursa(job #730138)

Utilizator BarracudaFMI-Alex Dobrin Barracuda Data 4 aprilie 2012 22:10:39
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<fstream>
#include<cstring>
using namespace std;


ifstream f("perle.in");
ofstream g("perle.out");
int a[10004],n,t;
int C(int x );
int B(int x);
int B(int x){
	
	if(x>n)
		return 0;
	if(a[x]==2)
		return B(x+1);
	
	if( x+3<n && 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(x+1<n && a[x]==1 &&  a[x+1]==2)
		return x+3;
	if(a[x]!=3)
		return 0;
	x=B(x+1);
	if(x!=0)
		return C(x);
	else
		return 0;
}
int main () {
	f>>t;
	for(;t;t--){
		f>>n;
		memset(a,0,sizeof(a));
		for(int i=1;i<=n;i++)
			f>>a[i];
		
		if(n==1 || (n>2 && (B(1)==n+1 || C(1)>=n)))
			g<<1<<"\n";
		else
			g<<0<<"\n";
	}
	f.close();
	g.close();
	return 0;
	
}