Cod sursa(job #2351955)

Utilizator danielsociuSociu Daniel danielsociu Data 22 februarie 2019 20:46:06
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORS(i,a,b) for(int i=(a);i<(b);++i)
#define PII pair<int,int>
#define vpp vector<PII>
#define all(x) x.begin(),b.end()
#define SZ(x) ((int)(x).size())
#define ll long long
#define maxn 10005

int n,l,s[maxn];

int C(int);
int B(int p){
	if(s[p]==2)return B(p+1);
	else if(s[p]==1&&s[p+2]==3)return C(p+4);
	return 0;
}

int C(int p){
	if(s[p]==2)return p+1;
	if(s[p]==3)return C(B(p+1));
	else if(s[p]==1&&s[p+1]==2) return p+3;
	return 0;
}

int main()
{
	freopen("perle.in","r",stdin);
	freopen("perle.out","w",stdout);
	cin>>n;
	for(;n--;){
		cin>>l;
		FORS(i,0,l)cin>>s[i];
		if(l==1||C(0)==l||B(0)==l)
			cout<<"1\n";
		else
			cout<<"0\n";
	}
}