Pagini recente » Cod sursa (job #2673363) | Cod sursa (job #1271669) | Cod sursa (job #2284490) | Cod sursa (job #1114067) | Cod sursa (job #2362073)
#include <cstdio>
const int MAX_L = 10000;
int s[5 + MAX_L];
int c(int pos);
int a(int pos) {
return pos + 1;
}
int b(int pos) {
if (s[pos] == 2)
return b(pos + 1);
else if (s[pos] == 1 && s[pos + 2] == 3)
return c(pos + 4);
}
int c(int pos) {
if (s[pos] == 2)
return pos + 1;
else if (s[pos] == 3)
return c(b(pos + 1));
else if (s[pos] == 1 && s[pos + 1] == 2)
return a(pos + 2);
}
int main() {
freopen("perle.in", "r", stdin);
freopen("perle.out", "w", stdout);
int t;
scanf("%d", &t);
for (int test = 0; test < t; test++) {
int l;
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;
}