답안 #591324

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
591324 2022-07-07T09:29:20 Z alextodoran Cubeword (CEOI19_cubeword) C++17
0 / 100
1100 ms 17996 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int ALPHA = 26 * 2;

const int MOD = 998244353;

int encode (char c) {
    return (islower(c) ? (int) (c - 'a') : 26 + (int) (c - 'A'));
}

int edges[ALPHA][ALPHA];
int between[ALPHA][ALPHA][ALPHA];
int full[ALPHA][ALPHA][ALPHA][ALPHA];

int solve () {
    for (int a = 0; a < ALPHA; a++) {
        for (int b = a; b < ALPHA; b++) {
            for (int c = b; c < ALPHA; c++) {
                between[a][b][c] = 0;
                for (int d = 0; d < ALPHA; d++) {
                    between[a][b][c] = (between[a][b][c] + (ll) edges[a][d] * edges[b][d] % MOD * edges[c][d]) % MOD;
                }
            }
        }
    }
    for (int a = 0; a < ALPHA; a++) {
        for (int b = a; b < ALPHA; b++) {
            for (int c = b; c < ALPHA; c++) {
                for (int d = c; d < ALPHA; d++) {
                    full[a][b][c][d] = (ll) between[a][b][c] * between[a][b][d] % MOD * between[a][c][d] % MOD * between[b][c][d] % MOD;
                }
            }
        }
    }
    ll answer = 0;
    for (int a = 0; a < ALPHA; a++) {
        for (int b = 0; b < ALPHA; b++) {
            for (int c = 0; c < ALPHA; c++) {
                for (int d = 0; d < ALPHA; d++) {
                    int v[] = {a, b, c, d};
                    sort(v, v + 4);
                    answer += full[v[0]][v[1]][v[2]][v[3]];
                }
            }
        }
    }
    answer %= MOD;
    return answer;
}

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

    int n;
    cin >> n;
    string word[n * 2];
    for (int i = 0; i < n; i++) {
        cin >> word[i];
        word[i + n] = word[i];
        reverse(word[i + n].begin(), word[i + n].end());
        if (word[i + n] < word[i]) {
            swap(word[i], word[i + n]);
        }
        if (word[i].front() != word[i].back()) {
            reverse(word[i + n].begin(), word[i + n].end());
        }
    }
    sort(word, word + n * 2);
    n = unique(word, word + n * 2) - word;
    int answer = 0;
    for (int k = 3; k <= 10; k++) {
        for (int a = 0; a < ALPHA; a++) {
            for (int b = 0; b < ALPHA; b++) {
                edges[a][b] = 0;
            }
        }
        for (int i = 0; i < n; i++) {
            if ((int) word[i].size() == k) {
                int a = encode(word[i].front());
                int b = encode(word[i].back());
                edges[a][b]++;
                if (a != b) {
                    edges[b][a]++;
                }
            }
        }
        answer += solve();
        if (answer >= MOD) {
            answer -= MOD;
        }
    }
    cout << answer << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1170 ms 17996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1170 ms 17996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1170 ms 17996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1170 ms 17996 KB Time limit exceeded
2 Halted 0 ms 0 KB -