Submission #518644

# Submission time Handle Problem Language Result Execution time Memory
518644 2022-01-24T10:47:57 Z Monarchuwu Cubeword (CEOI19_cubeword) C++17
0 / 100
250 ms 9456 KB
#include<iostream>
#include<algorithm>
#include<string>
#include<unordered_set>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;

const int N = 1e5 + 9, mod = 998244353;
int n;
int a[11][62][62][2];

bool palind(string s) {
    int l(0), r(s.size() - 1);
    while (l < r) {
        if (s[l] != s[r]) return false;
        ++l, --r;
    }
    return true;
}

int num(char c) {
    if ('a' <= c && c <= 'z') return c - 'a';
    if ('A' <= c && c <= 'A') return c - 'A' + 26;
    if ('0' <= c && c <= '9') return c - '0' + 52;
    return -1;
}

ll pw[N];
ll calc(int len, int i, int j) {
    if (i > j) swap(i, j);
    return a[len][i][j][1] + pw[a[len][i][j][0]];
}

int main() {
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> n;
    pw[1] = 2;
    for (int i = 2; i <= n; ++i) {
        pw[i] = pw[i - 1] << 1;
        if (pw[i] > mod) pw[i] -= mod;
    }

    unordered_set<string> S;
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        if (S.count(s)) continue;

        char c1(s[0]), c2(s.back());
        if (c1 > c2) swap(c1, c2);

        ++a[s.size()][num(c1)][num(c2)][palind(s)];
        reverse(all(s));
        S.insert(s);
    }

    ll ans(0);
    for (int len = 3; len <= 10; ++len)
        for (int i1 = 0; i1 < 6; ++i1)
            for (int i2 = 0; i2 < 6; ++i2)
                for (int i3 = 0; i3 < 6; ++i3)
                    for (int i4 = 0; i4 < 6; ++i4)
                        for (int i5 = 0; i5 < 6; ++i5)
                            for (int i6 = 0; i6 < 6; ++i6)
                                for (int i7 = 0; i7 < 6; ++i7)
                                    for (int i8 = 0; i8 < 6; ++i8) {
                                        ans += calc(len, i1, i2) * calc(len, i2, i3) % mod * calc(len, i3, i4) % mod * calc(len, i4, i1) % mod
                                            * calc(len, i1, i5) % mod * calc(len, i2, i6) % mod * calc(len, i3, i7) % mod * calc(len, i4, i8) % mod
                                            * calc(len, i5, i6) % mod * calc(len, i6, i7) % mod * calc(len, i7, i8) % mod * calc(len, i8, i5);
                                        ans %= mod;
                                    }
    cout << ans << '\n';
}
/**  /\_/\
 *  (= ._.)
 *  / >0  \>1
**/
# Verdict Execution time Memory Grader output
1 Incorrect 250 ms 9456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 250 ms 9456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 250 ms 9456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 250 ms 9456 KB Output isn't correct
2 Halted 0 ms 0 KB -