Pagini recente » Cod sursa (job #2606002) | Cod sursa (job #1343623) | Cod sursa (job #283441) | Cod sursa (job #1340710) | Cod sursa (job #2404308)
#include <cstdio>
const int MAX_L = 10000;
int s[5 + MAX_L];
int l;
int c(int pos);
int a(int pos) {
return pos + 1;
}
int b(int pos) {
if (s[pos] == 2)
return b(pos + 1);
if (s[pos] == 1 && s[pos + 2] == 3)
return c(pos + 4);
return l + 5;
}
int c(int pos) {
if (s[pos] == 2)
return pos + 1;
if (s[pos] == 3)
return c(b(pos + 1));
if (s[pos] == 1 && s[pos + 1] == 2)
return a(pos + 2);
return l + 5;
}
int main() {
freopen("perle.in", "r", stdin);
freopen("perle.out", "w", stdout);
int t;
scanf("%d", &t);
for (int test = 0; test < t; test++) {
scanf("%d", &l);
for (int i = 1; i <= l; i++)
scanf("%d", &s[i]);
if (a(1) == l + 1 || b(1) == l + 1 || c(1) == l + 1)
printf("1\n");
else
printf("0\n");
for (int i = 1; i <= l; i++)
s[i] = 0;
}
return 0;
}