Pagini recente » Cod sursa (job #2415848) | Cod sursa (job #2607656) | Cod sursa (job #2087572) | Cod sursa (job #1295065) | Cod sursa (job #2947567)
#include <bits/stdc++.h>
using namespace std;
ifstream in ("perle.in");
ofstream out("perle.out");
#define maxN 10000
int n,pos;
int v[maxN+1];
bool A();
bool B();
bool C();
bool A(){
if(pos>n){
return 0;
}
pos++;
return 1;
}
bool B(){
if(pos>n){
return 0;
}
if(v[pos]==3){
pos++;
return 0;
}
if(v[pos]==2){
pos++;
return B();
}
if(v[pos]==1 && v[pos+2]==3){
pos++;
if(A()==0){
return 0;
}
pos++;
return A() && C();
}
return 0;
}
bool C(){
if(pos>n){
return 0;
}
if(v[pos]==2){
pos++;
return 1;
}
if(v[pos]==1){
if(v[pos+1]==2){
pos+=2;
return A();
}
return 0;
}
pos++;
return B() && C();
}
int main(){
int q;
in>>q;
for(int z=1;z<=q;z++){
in>>n;
for(int i=1;i<=n;i++){
in>>v[i];
}
pos=1;
if(A() && pos>n){
out<<1<<'\n';
continue;
}
pos=1;
if(B() && pos>n){
out<<1<<'\n';
continue;
}
pos=1;
if(C() && pos>n){
out<<1<<'\n';
continue;
}
out<<0<<'\n';
}
}