Cod sursa(job #2923001)

Utilizator _andrei4567Stan Andrei _andrei4567 Data 11 septembrie 2022 00:20:33
Problema Perle Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <fstream>
#include <string.h>

using namespace std;

ifstream cin ("perle.in");
ofstream cout ("perle.out");

const int N = 1e4 + 1;
int a[N + 1];

int n, t;

int typec(int i);

int typeb (int i)
{
    if (a[i] == 2)
        return typeb(i + 1);
    if (a[i] == 1 && a[i + 2] == 3)
        return typec(i + 4);
    return -1;
}

int typec (int i)
{
    if (a[i] == 2)
        return i;
    if (a[i] == 1 && a[i + 1] == 2)
        return i + 2;
    if (a[i] == 3)
        return typeb(i + 1);
        return -1;
}

int main()
{
    for (cin >> t; t && cin >> n; --t)
    {
        memset (a, 0, sizeof(a));
        for (int i = 1; i <= n; ++i)cin >> a[i];
        if (n == 1 || typeb(1) == n || typec(1) == n)
            cout << "1\n";
        else
            cout << "0\n";

        }
    return 0;
}