Pagini recente » Cod sursa (job #1333255) | Cod sursa (job #2922692) | Cod sursa (job #1662406) | Cod sursa (job #2199533) | Cod sursa (job #1467048)
/**
* Worg
*/
#include <cstdio>
#include <stack>
#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];
stack <int> S;
void read_data() {
scanf("%d ", &n);
for(int i = 1; i <= n; ++i)
scanf("%d ", &V[i]);
}
bool check() {
int elem;
for(int pos = 1; pos <= n; ++pos) {
if( S.empty() )
return 0;
elem = S.top(); S.pop();
if( elem <= 3 && V[pos] != elem )
return 0;
if( elem == 5 ) {
if( V[pos] == 3 )
return 0;
if( V[pos] == 2 ) {
S.push(5);
}
else {
S.push(6); S.push(4); S.push(3); S.push(4);
}
}
if( elem == 6 ) {
if( V[pos] == 1 ) {
S.push(4); S.push(2);
}
if( V[pos] == 3 ) {
S.push(6); S.push(5);
}
}
}
if( S.size() )
return 0;
return 1;
}
void clean() {
while( !S.empty() )
S.pop();
}
int main() {
int t;
bool ans;
for(scanf("%d", &t); t; --t) {
read_data(); ans = 0;
S.push(4); ans = max(ans, check()); clean();
S.push(5); ans = max(ans, check()); clean();
S.push(6); ans = max(ans, check()); clean();
printf("%d\n", ans);
}
return 0;
}