Submission #853498

# Submission time Handle Problem Language Result Execution time Memory
853498 2023-09-24T12:45:59 Z Dec0Dedd Cubeword (CEOI19_cubeword) C++14
0 / 100
127 ms 17932 KB
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O3")

typedef long long ll;

const int MOD = 998244353;
const int L = 11;
const int A = 62;

set<string> st[L];
int n;
ll cnt[A][A], xx[A][A][A];
map<char, int> sc;

int sz;

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

    cin>>n;

    set<char> ss;
    for (int i=1; i<=n; ++i) {
        string s; cin>>s;
        st[s.size()].insert(s);
        reverse(s.begin(), s.end());
        st[s.size()].insert(s);
        ss.insert(s[0]), ss.insert(s.back());
    }

    int i=0;
    for (auto c : ss) sc[c]=i++;

    int ans=0;
    sz=ss.size();

    for (int l=3; l<L; ++l) {
        memset(cnt, 0, sizeof(cnt)), memset(xx, 0, sizeof(xx));
        for (auto u : st[l]) ++cnt[sc[(int)u[0]]][sc[(int)u.back()]];

        for (int i=0; i<sz; ++i) {
            for (int j=0; j<sz; ++j) {
                for (int k=0; k<sz; ++k) {
                    vector<int> v={i, j, k};

                    for (int d=0; d<sz; ++d) {
                        ll tp=1;
                        for (auto u : v) (tp*=cnt[d][u])%=MOD;
                        (xx[i][j][k]+=tp);
                        if (xx[i][j][k] >= MOD) xx[i][j][k]%=MOD;
                    }
                }
            }
        }

        for (int a=0; a<sz; ++a) {
            for (int b=a; b<sz; ++b) {
                for (int c=b; c<sz; ++c) {
                    for (int d=c; d<sz; ++d) {
                        ll x=(xx[a][b][c]*xx[a][b][d])%MOD*xx[a][c][d]%MOD*xx[b][c][d]%MOD;

                        if (a == d) x*=1;
                        else if ((a == b && b == c) || (b == c && c == d)) x*=4;
                        else if (a == b && c == d) x*=6;
                        else if (a == b || b == c || c == d) x*=12;
                        else x*=24;
                        (ans+=x)%=MOD;
                    }
                }
            }
        } 
    } cout<<ans<<"\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 17932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 17932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 17932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 17932 KB Output isn't correct
2 Halted 0 ms 0 KB -