Pagini recente » Cod sursa (job #1564397) | Cod sursa (job #126805) | Cod sursa (job #2248956) | Cod sursa (job #490499) | Cod sursa (job #2335054)
#include <cstdio>
using namespace std;
const int NMAX = 10005;
int v[NMAX];
int n;
int c(int poz);
int a(int poz) {
return poz + 1;
}
int b(int poz) {
if(v[poz] == 2) {
return b(poz + 1);
}
if(v[poz] == 1 && v[poz + 2] == 3) {
return c(poz + 4);
}
return 0;
}
int c(int poz) {
if(v[poz] == 2) {
return poz + 1;
}
if(v[poz] == 3) {
return c(b(poz + 1));
}
if(v[poz] == 1 && v[poz + 1] == 2) {
return a(poz + 2);
}
return 0;
}
int main() {
int T;
freopen("perle.in", "r", stdin);
freopen("perle.out", "w", stdout);
scanf("%d", &T);
while(T > 0) {
T--;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", &v[i]);
}
if(a(1) == n + 1 || b(1) == n + 1 || c(1) == n + 1) {
printf("1\n");
}
else {
printf("0\n");
}
}
return 0;
}