Pagini recente » Monitorul de evaluare | Cod sursa (job #1101656) | Cod sursa (job #1169769) | Cod sursa (job #356437) | Cod sursa (job #2205801)
#include <stdio.h>
int advanceC(const int& n, const int& pos, int x[]);
int advanceB(const int& n, const int& pos, int x[]) {
if (pos > n)
return 0;
if (x[pos] == 2)
return advanceB(n, pos + 1, x);
if (x[pos] == 1 && x[pos + 2] == 3)
return advanceC(n, pos + 4, x);
return 0;
}
int advanceC(const int& n, const int& pos, int x[]) {
if (pos > n)
return pos;
if (x[pos] == 2)
return pos + 1;
if (x[pos] == 3)
return advanceC(n, advanceB(n, pos + 1, x), x);
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);
int x[1 + n];
for (int i = 1; i <= n; i++)
scanf("%d", &x[i]);
if (n == 1 || advanceB(n, 1, x) == n + 1 || advanceC(n, 1, x) == n + 1)
printf("1\n");
else
printf("0\n");
}
fclose(stdin);
fclose(stdout);
return 0;
}