Cod sursa(job #2861257)

Utilizator mateitudordmDumitru Matei mateitudordm Data 3 martie 2022 19:06:35
Problema Episoade Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.53 kb
#include <fstream>
#define nmax 100
#define tmax 20

using namespace std;

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

struct lol
{
    int first, second, nr;
};
string s;
int ind = 0, v[nmax + 1], ok = 1, t, n, pozitie[nmax + 1];
lol ophtg();

lol getelem()
{
    if (s[ind] == '(')
    {
        ind++;
        lol aux = ophtg();
        ind++;
        return aux;
    }
    else
    {
        int nr = 0;
        while (isdigit(s[ind]))
            nr = nr * 10 + s[ind++] - '0';
        return {pozitie[nr], pozitie[nr], 1};
    }
}

lol opmm()
{
    lol poz = getelem(), aux, mm = poz;
    while (s[ind] == '>')
    {
        ind++;
        aux = getelem();
        if (poz.second + 1 != aux.first)
            ok = 0;
        mm.first = min(mm.first, aux.first);
        mm.second = max(mm.second, aux.second);
        mm.nr += aux.nr;
        poz = aux;
    }
    return mm;
}

lol ophtg()
{
    lol poz = opmm(), aux, mm;
    mm = poz;
    while (s[ind] == '#')
    {
        ind++;
        poz = opmm();
        mm.first = min(mm.first, poz.first);
        mm.second = max(mm.second, poz.second);
        mm.nr += poz.nr;
    }
    if (mm.second - mm.first + 1 != mm.nr)
        ok = 0;
    return mm;
}

int main()
{
    int i, j;
    cin >> s >> t >> n;
    while (t--)
    {
        for (i = 1; i <= n; i++)
            cin >> v[i], pozitie[v[i]] = i;
        ok = 1;
        ind = 0;
        ophtg();
        cout << ok << '\n';
    }
    return 0;
}