Cod sursa(job #2329282)

Utilizator mihai50000Mihai-Cristian Popescu mihai50000 Data 26 ianuarie 2019 15:40:14
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;
	
ifstream in("perle.in");
ofstream out("perle.out");
	
const int DIM = 1e4 + 7;

int v[DIM];

int perlaB(int pos);
int perlaC(int pos);

int n;

int perlaB(int pos)
{
	if(v[pos] == 2)
		return perlaB(pos + 1);
	
	if(v[pos] == 1 && v[pos + 2] == 3)
		return perlaC(pos + 4);
	
	return 0;
}

int perlaC(int pos)
{
	if(v[pos] == 2)
		return pos;
	
	if(v[pos] == 3)
		return perlaC(perlaB(pos + 1) + 1);
	
	if(v[pos] == 1 && v[pos + 1] == 2)
		return pos + 2;
	return 0;
}

int main()
{
	int t;
	in >> t;
	
	while(t--)
	{
		in >> n;
		
		for(int i = 1; i <= n; i++)
			in >> v[i];
		
		if(n == 1)
		{
			out << 1 << '\n';
			continue;
		}
		
		if(perlaB(1) == n || perlaC(1) == n)
			out << 1 << '\n';
		else
			out << 0 << '\n';
	}
}