Submission #1245501

#TimeUsernameProblemLanguageResultExecution timeMemory
1245501BlockOGCubeword (CEOI19_cubeword)C++20
0 / 100
1195 ms14988 KiB
#include <bits/stdc++.h>

// mrrrow meeow :3
// go play vivid/stasis now! it's free on steam

#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;

int ____init = [] {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    return 0;
}();

int main() {
    map<int, map<char, map<char, set<string>>>> data;

    int n;
    cin >> n;
    while (n--) {
        string s;
        cin >> s;
        data[s.size()][s[0]][s[s.size() - 1]].insert(s);
        reverse(be(s));
        data[s.size()][s[0]][s[s.size() - 1]].insert(s);
    }

    long long res = 0;
    for (auto [_, m] : data) {
        for (auto [a, bs] : m) {
            for (auto [b, bss] : bs) {
                long long n1 = bss.size();
                for (auto [c, css] : m[b]) {
                    long long n2 = (n1 * css.size()) % 998244353;
                    for (auto [d, dss] : m[c]) {
                        long long n3 = (n2 * css.size()) % 998244353;
                        if (m[d].count(a)) {
                            long long n4 = (n3 * m[d][a].size());

                            for (auto [e, fs] : m) {
                                for (auto [f, fss] : fs) {
                                    long long n5 = fss.size();
                                    for (auto [g, gss] : m[f]) {
                                        long long n6 = (n5 * gss.size()) % 998244353;
                                        for (auto [h, hss] : m[g]) {
                                            long long n7 = (n6 * gss.size()) % 998244353;
                                            if (m[h].count(e)) {
                                                long long n8 = (n7 * m[h][e].size());

                                                if (m[a].count(e) && m[b].count(f) && m[c].count(g) && m[d].count(h)) {
                                                    res = (res + n4 * n8 % 998244353 * m[a][e].size() % 998244353 * m[b][f].size() %
                                                                     998244353 * m[c][g].size() % 998244353 * m[d][h].size() % 998244353) %
                                                          998244353;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    cout << res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...