Submission #283458

# Submission time Handle Problem Language Result Execution time Memory
283458 2020-08-25T19:17:45 Z dolphingarlic Cubeword (CEOI19_cubeword) C++14
0 / 100
305 ms 17016 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll MOD = 998244353;

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

set<string> words[11];
ll cnt[62][62], dp[62][62][62], perm[8] = {24, 12, 12, 4, 12, 6, 4, 1};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        words[s.size()].insert(s);
        reverse(s.begin(), s.end());
        words[s.size()].insert(s);
    }

    ll ans = 0;
    for (int l = 3; l < 11; l++) {
        memset(cnt, 0, sizeof cnt);
        memset(dp, 0, sizeof dp);
        for (string i : words[l]) cnt[id(i[0])][id(i.back())]++;
        for (int i = 0; i < 62; i++) {
            for (int a = 0; a < 62; a++) {
                for (int b = a; b < 62; b++) {
                    for (int c = b; c < 62; c++) {
                        dp[a][b][c] = (dp[a][b][c] + cnt[i][a] * cnt[i][b] * cnt[i][c] % MOD) % MOD;
                    }
                }
            }
        }
        for (int a = 0; a < 62; a++) {
            for (int b = a; b < 62; b++) {
                for (int c = b; c < 62; c++) {
                    for (int d = c; d < 62; d++) {
                        int mask = (a == b) << 2 | (b == c) << 1 | (c == d);
                        ans = (ans + dp[a][b][c] * dp[a][b][d] * dp[a][c][d] % MOD * dp[b][c][d] * perm[mask] % MOD) % MOD;
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 305 ms 17016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 305 ms 17016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 305 ms 17016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 305 ms 17016 KB Output isn't correct
2 Halted 0 ms 0 KB -