Pagini recente » Cod sursa (job #1208531) | Cod sursa (job #1340179) | Cod sursa (job #175714) | Cod sursa (job #1301925) | Cod sursa (job #201812)
Cod sursa(job #201812)
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <algorithm>
#include <utility>
#include <string>
#include <functional>
#include <sstream>
#include <fstream>
using namespace std;
#define FOR(i,a,b) for (i=a;i<=b;i++)
#define fori(it,v) for (it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fs first
#define ss second
#define all(c) c.begin(),c.end()
#define pf push_front
#define popb pop_back
#define popf pop_front
int n,l;
int a[10001];
int test_b(int i);
int test_c(int i);
int test_b(int i)
{
for (; i<l; i++)
if (a[i]!=2) break;
if (i==l) return 0;
if (l < i+5) return 0;
if (a[i]!=1 || a[i+2]!=3) return 0;
return test_c(i+4);
}
int test_c(int i)
{
if (a[i]==2) return i+1; // 2
if (a[i]==1) // 12A
{
if (l < i+3) return 0;
if (a[i+1]==2) return i+3;
}
i=test_b(i+1); // 3BC
if (i==l || i==0) return 0;
return test_c(i);
}
int test()
{
if (l==1) return 1;
if (a[0]==1)
{
if (l==3 && a[1]==2) return 1; // 12A
if (l>=5 && a[2]==3) return (test_c(4) == l); // 1A3AC
}
if (a[0]==2)
return (test_b(0)==l); // 2B
return(test_c(0)==l); // 3BC
}
ifstream in("perle.in");
ofstream out("perle.out");
int main()
{
int i,j;
in>>n;
FOR(i,1,n)
{
in>>l;
FOR(j,0,l-1)
in>>a[j];
out<<test()<<'\n';
}
in.close();
out.close();
return 0;
}