Pagini recente » Cod sursa (job #2651489) | Cod sursa (job #1960617) | Cod sursa (job #2473964) | Cod sursa (job #1304702) | Cod sursa (job #2457343)
#include <iostream>
#include <fstream>
#define MaxL 10001
using namespace std;
ifstream f("perle.in");
ofstream g("perle.out");
int l,i,n;
short x[MaxL];
bool perlaB();
bool perlaC()
{
if(i==l)
return x[i]==2;
if(l==i+2)
return x[i]==1 && x[i+1]==2;
if(x[i]==3)
{
i++;
if(perlaB())
return perlaC();
else
return false;
}
else return false;
}
bool perlaB()
{
while(x[i]==2)
i++;
if(i+4<=l)
{
int j=i;
i+=4;
return x[j]==1 && x[j+2]==3 && perlaC();
}
else
return false;
}
bool solve()
{
i=1;
if(l==1)
return true;
if(l==3 && x[1]==1 && x[2]==2)
return true;
if(x[1]==3)
return perlaC();
else
return perlaB();
}
int main()
{
f>>n;
for(int i=1;i<=n;i++)
{
f>>l;
for(int i=1;i<=l;i++)
f>>x[i];
g<<solve()<<'\n';
}
f.close();
g.close();
return 0;
}