Pagini recente » Cod sursa (job #743495) | Cod sursa (job #3041051) | Cod sursa (job #1627549) | Cod sursa (job #2326873) | Cod sursa (job #2116996)
#include <fstream>
using namespace std;
ifstream fin ("perle.in"); ofstream fout ("perle.out");
const int nmax = 1e4;
int n, pos;
int v[nmax + 1];
void C ();
void A () {
if (pos != 0)
++ pos;
}
void B () {
if (pos == 0)
return ;
if (v[ pos ] == 2) {
++ pos;
B ();
} else if (v[ pos ] == 1) {
++ pos;
A ();
if (v[ pos ] != 3) {
pos = 0;
return ;
}
++ pos;
A ();
C ();
} else {
pos = 0;
}
}
void C () {
if (pos == 0)
return ;
if (v[ pos ] == 2) {
++ pos;
} else if (v[ pos ] == 1) {
++ pos;
if (v[ pos ] != 2) {
pos = 0;
return ;
}
++ pos;
A ();
} else {
++ pos;
B ();
C ();
}
}
void solve () {
fin >> n;
for (int i = 1; i <= n; ++ i)
fin >> v[ i ];
bool ok = 0;
pos = 1; A ();
if (pos == n + 1)
ok = 1;
pos = 1; B ();
if (pos == n + 1)
ok = 1;
pos = 1; C ();
if (pos == n + 1)
ok = 1;
fout << ok << "\n";
}
int main () {
int t;
fin >> t;
while (t --) {
solve ();
}
fin.close();
fout.close();
return 0;
}