Submission #1232735

#TimeUsernameProblemLanguageResultExecution timeMemory
1232735Tenis0206Cubeword (CEOI19_cubeword)C++20
21 / 100
1195 ms17088 KiB
#include <bits/stdc++.h>

using namespace std;

const int Mod = 998244353;

int n;

int cnt[15][155][155];
int tri[15][155][155][155];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef home
    freopen("nr.in","r",stdin);
    freopen("nr.out","w",stdout);
    #endif // home
    cin>>n;
    set<string> l;
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        l.insert(s);
        reverse(s.begin(), s.end());
        l.insert(s);
    }
    vector<char> ch;
    for(auto it=l.begin();it!=l.end();it++)
    {
        string s = *it;
        ++cnt[s.size()][s.front()][s.back()];
        ch.push_back(s.front());
        ch.push_back(s.back());
    }
    sort(ch.begin(), ch.end());
    vector<char> aux;
    for(auto it : ch)
    {
        if(aux.empty() || it != aux.back())
        {
            aux.push_back(it);
        }
    }
    ch = aux;
    long long rez = 0;
    for(int len=3;len<=10;len++)
    {
        for(auto a : ch)
        {
            for(auto h : ch)
            {
                for(auto f : ch)
                {
                    for(auto e : ch)
                    {
                        tri[len][a][h][f] += 1LL * cnt[len][a][e] * cnt[len][h][e] % Mod * cnt[len][f][e] % Mod;
                        tri[len][a][h][f] %= Mod;
                    }
                }
            }
        }
        for(auto a : ch)
        {
            for(auto h : ch)
            {
                for(auto f : ch)
                {
                    for(auto d : ch)
                    {
                        for(auto g : ch)
                        {
                            for(auto b : ch)
                            {
                                rez += 1LL * tri[len][a][h][f] * tri[len][d][g][b] % Mod * cnt[len][d][a] % Mod * cnt[len][a][b] % Mod * cnt[len][b][f] % Mod * cnt[len][d][h] % Mod * cnt[len][h][g] % Mod * cnt[len][g][f] % Mod;
                                rez %= Mod;
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<rez<<'\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...