Submission #275996

# Submission time Handle Problem Language Result Execution time Memory
275996 2020-08-20T09:07:54 Z egekabas Cubeword (CEOI19_cubeword) C++14
0 / 100
1100 ms 7280 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
ll mod = 998244353;
ll ans = 0;
vector<string> a[11];
ll n = 62;
ll cnt[70][70];
map<char, ll> mpp;
ll dp[70][70][70];


void solve(int cur){
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            cnt[i][j] = 0;
    int sz = a[cur].size();
    for(int i = 0;  i < sz; ++i){
        string u = a[cur][i];
        reverse(all(u));
        a[cur].pb(u);
    }
    sort(all(a[cur]));
    a[cur].resize(unique(all(a[cur]))-a[cur].begin());
    for(auto u : a[cur]){
        cnt[mpp[u[0]]][mpp[u.back()]]++;
    }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            for(int k = 0; k < n; ++k){
                dp[i][j][k] = 0;
                for(int mid = 0; mid < n; ++mid){
                    dp[i][j][k] += cnt[mid][i]*cnt[mid][j]%mod*cnt[mid][k]%mod;
                    if(dp[i][j][k] >= mod)
                        dp[i][j][k] -= mod;
                }
            }
    for(int i = 0; i < n; ++i)
        for(int k = 0; k < n; ++k)
            for(int y = 0; y < n; ++y)
                for(int j = 0; j < n; ++j){
                    ans += dp[i][k][j]*dp[i][j][y]%mod*dp[y][j][k]%mod*dp[i][k][y]%mod;
                    if(ans >= mod)
                        ans -= mod;
                }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    ll t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        a[s.size()].pb(s);
    }
    ll cnt = 0;
    for(char i = 'a'; i <= 'z'; ++i)
        mpp[i] = cnt++;
    for(char i = 'A'; i <= 'Z'; ++i)
        mpp[i] = cnt++;
    for(char i = '0'; i <= '9'; ++i)
        mpp[i] = cnt++;
    n = cnt;
    for(ll i = 3; i <= 10; ++i)
        if(a[i].size())
            solve(i);
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1196 ms 7280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1196 ms 7280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1196 ms 7280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1196 ms 7280 KB Time limit exceeded
2 Halted 0 ms 0 KB -