Pagini recente » Cod sursa (job #21544) | Cod sursa (job #115664) | Cod sursa (job #2488674) | Cod sursa (job #1001764) | Cod sursa (job #2810400)
#include <bits/stdc++.h>
using namespace std;
int const N = 10001 , inf = (1 << 30);
ifstream fin("perle.in");
ofstream fout("perle.out");
int v[N] , n;
int C(int p);
int B(int p){
if(p > n)
return inf;
if(v[p] == 2)
return B(p + 1);
if(v[p] == 1 && v[p + 2] == 3)
return C(p + 4);
return inf;
}
int C(int p){
if(p > n)
return inf;
if(v[p] == 2)
return p + 1;
if(v[p] == 1 && v[p + 1] == 2)
return p + 3;
if(v[p] == 3)
return C(B(p + 1));
return inf;
}
int main()
{
int t;
fin >> t;
while(t --){
fin >> n;
for(int i = 1 ; i <= n ; ++ i)
fin >> v[i];
if(n == 1){
fout << "1\n";
continue;
}
fout << (((B(1) == n + 1) || (C(1) == n + 1)) ? "1\n" : "0\n");
}
return 0;
}