Pagini recente » Cod sursa (job #876594) | Rating Vlad Cociorva (vladcociorva) | Arhiva de probleme | Cod sursa (job #1177126) | Cod sursa (job #730138)
Cod sursa(job #730138)
#include<fstream>
#include<cstring>
using namespace std;
ifstream f("perle.in");
ofstream g("perle.out");
int a[10004],n,t;
int C(int x );
int B(int x);
int B(int x){
if(x>n)
return 0;
if(a[x]==2)
return B(x+1);
if( x+3<n && a[x]==1 && a[x+2]==3)
return C(x+4);
return 0;
}
int C(int x){
if(a[x]==2)
return x+1;
if(x+1<n && a[x]==1 && a[x+1]==2)
return x+3;
if(a[x]!=3)
return 0;
x=B(x+1);
if(x!=0)
return C(x);
else
return 0;
}
int main () {
f>>t;
for(;t;t--){
f>>n;
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++)
f>>a[i];
if(n==1 || (n>2 && (B(1)==n+1 || C(1)>=n)))
g<<1<<"\n";
else
g<<0<<"\n";
}
f.close();
g.close();
return 0;
}