Pagini recente » Cod sursa (job #1506031) | Cod sursa (job #696549) | Rating Badea Razvan Theodor (slym20) | Profil FlorinHaja | Cod sursa (job #2553527)
#include <bits/stdc++.h>
using namespace std;
int sirag[10001];
int testA(int left, int right);
int testB(int left, int right);
int testC(int left, int right);
int testA(int left, int right)
{
return right - left == 1 ? left + 1 : 0;
}
int testB(int left, int right)
{
while (left < right && sirag[left] == 2)
left++;
if (right - left >= 5 && sirag[left] == 1 && sirag[left+2] == 3)
return testC(left + 4, right);
return 0;
}
int testC(int left, int right)
{
switch (sirag[left])
{
case 1:
return right - left == 3 && sirag[left+1] == 2 ? left + 3 : 0;
case 2:
return left + 1;
case 3:
if (right - left < 7 || sirag[left+1] == 3)
return 0;
else
{
int leftB = testB(left + 1, right);
if (leftB)
return testC(leftB, right);
}
return 0;
default:
return 0;
}
}
int test(int len)
{
return testA(0, len) == len || testB(0, len) == len || testC(0, len) == len;
}
int main()
{
ifstream in("perle.in");
ofstream out("perle.out");
//istream &in = cin;
//ostream &out = cout;
int n;
in >> n;
while (--n >= 0)
{
int len;
in >> len;
for (int i = 0; i < len; i++)
in >> sirag[i];
out << test(len) << endl;
}
}