Pagini recente » Cod sursa (job #1633978) | Cod sursa (job #2531302) | Cod sursa (job #607739) | Cod sursa (job #2347553) | Cod sursa (job #880504)
Cod sursa(job #880504)
#include <fstream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
int n, t, v[20000];
long B(long x);
long C(long x);
long B(long x)
{
if(x > n)
return 0;
if(v[x] == 2)
return B(x+1);
if(v[x]==1 && v[x+2]==3)
return C(x+4);
return 0;
}
long C(long x)
{
if(x > n)
return 0;
if(v[x] == 2)
return x;
if(v[x]==1 && v[x+1]==2)
return x+2;
if(v[x] == 3)
{
long aux = B(x+1);
if(aux)
return C(aux+1);
}
}
int main()
{
ifstream fin("perle.in");
ofstream fout("perle.out");
//Read
fin>>t;
//Compute
for(int i=1; i<=t; i++)
{
fin>>n;
for(int j=1; j<=n; j++)
fin>>v[j];
if(n==1 || n==B(1) || n==C(1))
fout<<"1"<<'\n';
else
fout<<"0"<<'\n';
}
}