Pagini recente » Cod sursa (job #60848) | Cod sursa (job #1147534) | Cod sursa (job #2165957) | Cod sursa (job #3262975) | Cod sursa (job #761089)
Cod sursa(job #761089)
#include <cstdio>
#include <cstdlib>
using namespace std;
int N, T, v[10010];
int B(int pos);
int C(int pos);
int main()
{
freopen("perle.in", "r", stdin);
freopen("perle.out", "w", stdout);
int i;
scanf("%i", &T);
while(T --)
{
scanf("%i", &N);
for(i = 1; i <= N; i++) scanf("%i", &v[i]);
if(N == 1) printf("1\n");
else
{
int x = B(1);
if(x != N + 1) x = C(1);
if(x == N + 1) printf("1\n");
else printf("0\n");
}
}
return 0;
}
int B(int pos)
{
if(pos > N + 1) return pos;
if(v[pos] == 2) return B(pos + 1);
if(v[pos] == 1 && v[pos + 2] == 3) return C(pos + 4);
return N + 2;
}
int C(int pos)
{
if(pos > N + 1) return pos;
if(v[pos] == 2) return pos + 1;
if(v[pos] == 3) return C(B(pos + 1));
if(v[pos] == 1 && v[pos + 1] == 2) return pos + 3;
return N + 2;
}