1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <vector>
#include <set>

using namespace std;

struct Element
{
    long long bilans;
    string napis;
};

long long n = 0;
string wczytany_ciag;
vector<string> napisy;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> wczytany_ciag;
        napisy.push_back(wczytany_ciag);
    }

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            set<string> S;
            vector<Element> elem;
            string do_iteracji = napisy[i] + napisy[j];
            for (int k = 0; k < do_iteracji.size(); ++k)
            {
                if (elem.empty())
                {
                    if (do_iteracji[k] == 'L')
                        elem.push_back({1,"L"});
                }
                else if (do_iteracji[k] == 'L')
                {
                    vector<Element> do_dodania;
                    for (int f = 0; f < elem.size(); ++f)
                    {
                        do_dodania.push_back({elem[f].bilans+1,elem[f].napis + (string)"L"});
                    }
                    for (int f = 0; f < do_dodania.size(); ++f)
                    {
                        elem.push_back(do_dodania[f]);
                    }
                }
                else
                {
                    vector<Element> do_dodania;
                    for (int f = 0; f < elem.size(); ++f)
                    {
                        if (elem[f].bilans-1 >= 0)
                            do_dodania.push_back({elem[f].bilans-1,elem[f].napis + (string)"P"});
                    }
                    for (int f = 0; f < do_dodania.size(); ++f)
                    {
                        if (do_dodania[f].bilans == 0)
                            S.insert(do_dodania[f].napis);
                        elem.push_back(do_dodania[f]);
                    }
                }
            }
            printf("%lld ",S.size());
        }
        printf("\n");
    }
    return 0;
}