제출 #900536

#제출 시각아이디문제언어결과실행 시간메모리
900536Shayan86Cubeword (CEOI19_cubeword)C++14
100 / 100
622 ms10376 KiB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define Mp          make_pair
#define sep         ' '
#define endl        '\n'
#define F	        first
#define S	        second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define kill(res)	cout << res << '\n', exit(0);
#define set_dec(x)	cout << fixed << setprecision(x);
#define fast_io     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io     freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);

const ll S = 11;
const ll C = 65;
const ll N = 1e5 + 50;
const ll Mod = 998244353;

ll n, m, cnt[C][C], val[C][C][C];

vector<string> vec[S];

int id(char x){
    if('a' <= x && x <= 'z') return x - 'a';
    if('A' <= x && x <= 'Z') return x - 'A' + 26;
    return x - '0' + 52;
}

int main(){
    fast_io;

    cin >> n;

    for(int i = 1; i <= n; i++){
        string s; cin >> s;
        vec[s.size()].pb(s);
        reverse(all(s));
        vec[s.size()].pb(s);
    }

    for(int i = 3; i <= 10; i++){
        sort(all(vec[i]));
        vec[i].resize(unique(all(vec[i])) - vec[i].begin());
    }

    ll res = 0;
    for(int i = 3; i <= 10; i++){
        for(int j = 0; j < C; j++) for(int k = 0; k < C; k++) cnt[j][k] = 0;
        for(int j = 0; j < C; j++) for(int k = 0; k < C; k++) for(int c = 0; c < C; c++) val[j][k][c] = 0;

        for(auto j: vec[i]) cnt[id(j[0])][id(j[i-1])]++;

        for(int a = 0; a < C; a++)
            for(int b = a; b < C; b++)
                for(int c = b; c < C; c++)
                    for(int j = 0; j < C; j++)
                        val[a][b][c] = (val[a][b][c] + (cnt[a][j] * cnt[b][j] % Mod * cnt[c][j])) % Mod;

        for(int a = 0; a < C; a++)
            for(int b = a; b < C; b++)
                for(int c = b; c < C; c++)
                    for(int d = c; d < C; d++){
                        ll th = val[a][b][c] * val[a][b][d] % Mod * val[a][c][d] % Mod * val[b][c][d] % Mod;

                        ll z = 24;
                        vector<int> ops;
                        ops.pb(a); ops.pb(b); ops.pb(c); ops.pb(d);
                        ops.resize(unique(all(ops)) - ops.begin());

                        if(ops.size() == 1) z = 1;
                        if(ops.size() == 2){
                            z = 4;
                            if(a == b && c == d) z = 6;
                        }
                        if(ops.size() == 3) z = 12;

                        res = (res + th * z) % Mod;
                    }
    }

    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...