Cod sursa(job #2157352)
Utilizator | Data | 9 martie 2018 15:50:40 | |
---|---|---|---|
Problema | Perle | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.64 kb |
#include <fstream>
using namespace std;
ifstream cin("perle.in");
ofstream cout("perle.out");
int l,i,j,n,v[10002],x;
void c(int &x);
void b(int &x);
void b(int &x)
{
if(x<=l)
{
if(v[x]==2)
{
x++;
b(x);
}
else
{
if(v[x]==1&&x+2<=l)
{
x=x+2;
if(v[x]==3&&x+2<=l)
{
x=x+2;
c(x);
}
}
}
}
}
void c(int &x)
{
if(x<=l)
{
if(v[x]==2)
x++;
else
{
if(v[x]==3)
{
x++;
b(x);
x++;
c(x);
}
else
{
if(v[x]==1&&x+1<=l)
{
x++;
if(v[x]==2&&x+1<=l)
x++;
}
}
}
}
}
int main()
{
cin>>n;
for(i=1;i<=n;i++)
{
cin>>l;
for(j=1;j<=l;j++)
cin>>v[j];
if(l==1)
{
if(v[1]<=3)
cout<<1<<'\n';
else
cout<<0<<'\n';
}
else
{
x=1;
b(x);
if(x==l+1)
cout<<1<<'\n';
else
{
x=1;
c(x);
if(x==l+1)
cout<<1<<'\n';
else
cout<<0<<'\n';
}
}
}
return 0;
}