Pagini recente » Cod sursa (job #1182252) | Cod sursa (job #1181089) | Cod sursa (job #1243403) | Cod sursa (job #498931) | Cod sursa (job #2272525)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10005;
int n;
int v[MAXN];
int A(int poz);
int B(int poz);
int C(int poz);
int C(int poz) {
if (v[poz] == 2)
return poz + 1;
if (poz >= n)
return 0;
if (v[poz] == 3)
return C(B(poz + 1));
if (poz + 2 <= n && v[poz] == 1 && v[poz + 1] == 2)
return A(poz + 2);
return 0;
}
int B(int poz) {
if (poz >= n)
return 0;
if (v[poz] == 2)
return B(poz + 1);
if (poz + 4 <= n && v[poz] == 1 && v[poz + 2] == 3)
return C(poz + 4);
return 0;
}
int A(int poz) {
return poz + 1;
}
int main() {
freopen("perle.in", "r", stdin);
freopen("perle.out", "w", stdout);
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &v[i]);
printf("%d\n", (A(1) == n + 1) | (B(1) == n + 1) | (C(1) == n + 1));
}
return 0;
}