Cod sursa(job #880504)

Utilizator Detrol2kGuianu Leon Detrol2k Data 16 februarie 2013 20:51:24
Problema Perle Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

int n, t, v[20000];

long B(long x);
long C(long x);

long B(long x)
{
	if(x > n)
		return 0;
	if(v[x] == 2)
		return B(x+1);
	if(v[x]==1 && v[x+2]==3)
		return C(x+4);
	return 0;
}

long C(long x)
{
	if(x > n)
		return 0;
	if(v[x] == 2)
		return x;
	if(v[x]==1 && v[x+1]==2)
		return x+2;
	if(v[x] == 3)
	{
		long aux = B(x+1);
		if(aux)
			return C(aux+1);
	}
}

int main()
{
	ifstream fin("perle.in");
	ofstream fout("perle.out");
	
	//Read
	fin>>t;

	//Compute
	for(int i=1; i<=t; i++)
	{
		fin>>n;
		for(int j=1; j<=n; j++)
			fin>>v[j];
		if(n==1 || n==B(1) || n==C(1))
			fout<<"1"<<'\n'; 
		else
			fout<<"0"<<'\n';		
	}
}