Pagini recente » Cod sursa (job #1418773) | Cod sursa (job #2166150) | Monitorul de evaluare | Cod sursa (job #1685583) | Cod sursa (job #2205803)
#include <stdio.h>
int x[10005];
int advanceC(const int& n, const int& pos);
int advanceB(const int& n, const int& pos) {
if (pos > n)
return 0;
if (x[pos] == 2)
return advanceB(n, pos + 1);
if (x[pos] == 1 && x[pos + 2] == 3)
return advanceC(n, pos + 4);
return 0;
}
int advanceC(const int& n, const int& pos) {
if (pos > n)
return 0;
if (x[pos] == 2)
return pos + 1;
if (x[pos] == 3)
return advanceC(n, advanceB(n, pos + 1));
if (pos + 1 <= n && x[pos] == 1 && x[pos + 1] == 2)
return pos + 3;
return 0;
}
int main() {
freopen("perle.in", "r", stdin);
freopen("perle.out", "w", stdout);
int Q;
scanf("%d", &Q);
while(Q--) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &x[i]);
if (n == 1 || advanceB(n, 1) == n + 1 || advanceC(n, 1) == n + 1)
printf("1\n");
else
printf("0\n");
}
fclose(stdin);
fclose(stdout);
return 0;
}