Cod sursa(job #3376997)

Utilizator popescu_georgePopescu George popescu_george Data 21 noiembrie 2026 07:22:22
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.44 kb
#include<fstream>
using namespace std;
ifstream cin("perle.in");
ofstream cout("perle.out");
int s[10001];
int C(int x);
int B(int x)
{
	return s[x]==1&&s[x+2]==3?C(x+4):s[x]==2?B(x+1):0;
}
int C(int x)
{
	return s[x]==2?x+1:s[x]==3?C(B(x+1)):s[x]==1&&s[x+1]==2?x+3:0;
}
int main()
{
	int n;
	for(cin>>n;n--;) {
		cin>>s[0];
		for(int i=1;i<=s[0];cin>>s[i++]);
		cout<<(s[0]==1||B(1)==s[0]+1||C(1)==s[0]+1)<<'\n';
	}
	return 0;
}