Pagini recente » Cod sursa (job #1488190) | Cod sursa (job #1913742) | Cod sursa (job #1942043) | Cod sursa (job #1440742) | Cod sursa (job #1466741)
/**
* Worg
*/
#include <cstdio>
#include <queue>
#define DIM 10010
using namespace std;
FILE *fin=freopen("perle.in","r",stdin);
FILE *fout=freopen("perle.out","w",stdout);
int n;
int V[DIM];
queue <int> Q;
void read_data() {
scanf("%d ", &n);
for(int i = 1; i <= n; ++i)
scanf("%d ", &V[i]);
}
bool check() {
for(int pos = 1; pos <= n; ++pos) {
if( Q.empty() )
return 0;
if( Q.front() <= 3 && V[pos] != Q.front() )
return 0;
if( Q.front() == 5 ) {
if( V[pos] == 3 )
return 0;
if( V[pos] == 2 ) {
Q.push(5);
}
else {
Q.push(4); Q.push(3); Q.push(4); Q.push(6);
}
}
if( Q.front() == 6 ) {
if( V[pos] == 1 ) {
Q.push(2); Q.push(4);
}
if( V[pos] == 3 ) {
Q.push(5); Q.push(6);
}
}
Q.pop();
if(pos + Q.size() > n)
return 0;
}
return 1;
}
void clean() {
while( !Q.empty() )
Q.pop();
}
int main() {
int t;
bool ans;
for(scanf("%d", &t); t; --t) {
read_data(); ans = 0;
Q.push(4); ans = max(ans, check()); clean();
Q.push(5); ans = max(ans, check()); clean();
Q.push(6); ans = max(ans, check()); clean();
printf("%d\n", ans);
}
return 0;
}