Pagini recente » Cod sursa (job #380137) | Cod sursa (job #380465) | Cod sursa (job #2229592) | Cod sursa (job #2338078) | Cod sursa (job #3266243)
#include <fstream>
using namespace std;
ifstream cin("perle.in");
ofstream cout("perle.out");
int q, n, ant, v[10001], poz;
bool B();
bool C();
bool B() {
bool ok=1;
if (v[poz]==2)
{
poz++;
if (!(v[poz]==1 || v[poz]==2) || poz>=n)
return 0;
return B();
}
else
{
poz+=2;
if (poz>=n)
return 0;
if (v[poz]!=3)
return 0;
poz++;
if (poz>=n)
return 0;
poz++;
if (poz>n)
return 0;
if (v[poz]==2 and poz==n)
return 1;
if (v[poz]==2)
return 0;
if (v[poz]==1 and v[poz+1]==2 and poz+2==n)
return 1;
if (v[poz]==1)
return 0;
return C();
}
}
bool C() {
if (v[poz]==1 and v[poz+1]==2 and poz+2==n)
return 1;
if (v[poz]==1)
return 0;
if (v[poz]==2 and poz==n)
return 1;
if (v[poz]==2)
return 0;
if (v[poz]==3 and poz<n)
{
if (B())
return C();
return 0;
}
return 0;
}
int main() {
cin>>q;
while (q--)
{
for (int i=1; i<=ant; i++)
v[i]=0;
cin>>n;
ant= n;
bool ok=1;
poz= 1;
for (int i=1; i<=n; i++)
{
cin>>v[i];
if (!(v[i]==1 || v[i]==2 || v[i]==3))
ok=0;
}
if (!ok)
{
cout<< 0 <<"\n";
continue;
}
if (n==1)
{
cout<< 1 <<"\n";
continue;
}
if (n==3 and v[1]==1 and v[2]==2)
{
cout<< 1 <<"\n";
continue;
}
if (v[1]==1)
{
cout<< B() <<"\n";
continue;
}
if (v[1]==2)
{
cout<< B() <<"\n";
continue;
}
cout<< C() <<"\n";
}
return 0;
}