Submission #591327

# Submission time Handle Problem Language Result Execution time Memory
591327 2022-07-07T09:49:55 Z alextodoran Cubeword (CEOI19_cubeword) C++17
100 / 100
227 ms 8232 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

//#pragma GCC optimize ("fast-math,unroll-loops")
//#pragma GCC target ("avx2,tune=native,bmi,bmi2")

using namespace std;

typedef long long ll;

const int ALPHA = 26 + 26 + 10;

const int MOD = 998244353;

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

vector <int> adj[ALPHA];

int edges[ALPHA][ALPHA];
int between[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++) {
        for (int i = 0; i < (int) adj[d].size(); i++) {
            int a = adj[d][i];
            for (int j = i; j < (int) adj[d].size(); j++) {
                int b = adj[d][j];
                for (int k = j; k < (int) adj[d].size(); k++) {
                    int c = adj[d][k];
                    between[a][b][c] = (between[a][b][c] + (ll) edges[a][d] * edges[b][d] % MOD * edges[c][d]) % MOD;
                }
            }
        }
    }
    ll answer = 0;
    for (int a = 0; a < ALPHA; a++) {
        for (int b = a; b < ALPHA; b++) {
            for (int c = b; c < ALPHA; c++) {
                if (between[a][b][c] > 0) {
                    for (int d = c; d < ALPHA; d++) {
                        ll ways = (ll) between[a][b][c] * between[a][b][d] % MOD * between[a][c][d] % MOD * between[b][c][d] % MOD;
                        if (a == b && b == c && c == d) {
                            ways *= 1;
                        } else if ((a == b && b == c) || (b == c && c == d)) {
                            ways *= 4;
                        } else if (a == b && c == d) {
                            ways *= 6;
                        } else if (a == b || b == c || c == d) {
                            ways *= 12;
                        } else {
                            ways *= 24;
                        }
                        answer += ways;
                    }
                }
            }
        }
    }
    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;
            }
            adj[a].clear();
        }
        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]++;
                }
            }
        }
        for (int a = 0; a < ALPHA; a++) {
            for (int b = 0; b <= ALPHA; b++) {
                if (edges[a][b] > 0) {
                    adj[a].push_back(b);
                }
            }
        }
        answer += solve();
        if (answer >= MOD) {
            answer -= MOD;
        }
    }
    cout << answer << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 77 ms 7376 KB Output is correct
2 Correct 83 ms 8116 KB Output is correct
3 Correct 86 ms 8104 KB Output is correct
4 Correct 75 ms 8232 KB Output is correct
5 Correct 77 ms 8076 KB Output is correct
6 Correct 82 ms 8088 KB Output is correct
7 Correct 80 ms 8080 KB Output is correct
8 Correct 78 ms 8092 KB Output is correct
9 Correct 91 ms 8084 KB Output is correct
10 Correct 81 ms 8076 KB Output is correct
11 Correct 80 ms 8080 KB Output is correct
12 Correct 84 ms 8076 KB Output is correct
13 Correct 73 ms 8068 KB Output is correct
14 Correct 78 ms 8076 KB Output is correct
15 Correct 74 ms 8072 KB Output is correct
16 Correct 81 ms 8088 KB Output is correct
17 Correct 73 ms 8084 KB Output is correct
18 Correct 82 ms 8072 KB Output is correct
19 Correct 69 ms 8084 KB Output is correct
20 Correct 77 ms 8076 KB Output is correct
21 Correct 85 ms 8088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 7376 KB Output is correct
2 Correct 83 ms 8116 KB Output is correct
3 Correct 86 ms 8104 KB Output is correct
4 Correct 75 ms 8232 KB Output is correct
5 Correct 77 ms 8076 KB Output is correct
6 Correct 82 ms 8088 KB Output is correct
7 Correct 80 ms 8080 KB Output is correct
8 Correct 78 ms 8092 KB Output is correct
9 Correct 91 ms 8084 KB Output is correct
10 Correct 81 ms 8076 KB Output is correct
11 Correct 80 ms 8080 KB Output is correct
12 Correct 84 ms 8076 KB Output is correct
13 Correct 73 ms 8068 KB Output is correct
14 Correct 78 ms 8076 KB Output is correct
15 Correct 74 ms 8072 KB Output is correct
16 Correct 81 ms 8088 KB Output is correct
17 Correct 73 ms 8084 KB Output is correct
18 Correct 82 ms 8072 KB Output is correct
19 Correct 69 ms 8084 KB Output is correct
20 Correct 77 ms 8076 KB Output is correct
21 Correct 85 ms 8088 KB Output is correct
22 Correct 87 ms 7996 KB Output is correct
23 Correct 89 ms 7992 KB Output is correct
24 Correct 78 ms 7988 KB Output is correct
25 Correct 81 ms 7992 KB Output is correct
26 Correct 82 ms 7988 KB Output is correct
27 Correct 74 ms 7996 KB Output is correct
28 Correct 78 ms 8088 KB Output is correct
29 Correct 79 ms 7984 KB Output is correct
30 Correct 84 ms 8000 KB Output is correct
31 Correct 94 ms 7988 KB Output is correct
32 Correct 78 ms 7992 KB Output is correct
33 Correct 77 ms 7988 KB Output is correct
34 Correct 77 ms 7988 KB Output is correct
35 Correct 102 ms 8020 KB Output is correct
36 Correct 72 ms 7988 KB Output is correct
37 Correct 77 ms 7988 KB Output is correct
38 Correct 80 ms 8028 KB Output is correct
39 Correct 81 ms 7980 KB Output is correct
40 Correct 77 ms 8032 KB Output is correct
41 Correct 78 ms 7996 KB Output is correct
42 Correct 76 ms 7984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 7376 KB Output is correct
2 Correct 83 ms 8116 KB Output is correct
3 Correct 86 ms 8104 KB Output is correct
4 Correct 75 ms 8232 KB Output is correct
5 Correct 77 ms 8076 KB Output is correct
6 Correct 82 ms 8088 KB Output is correct
7 Correct 80 ms 8080 KB Output is correct
8 Correct 78 ms 8092 KB Output is correct
9 Correct 91 ms 8084 KB Output is correct
10 Correct 81 ms 8076 KB Output is correct
11 Correct 80 ms 8080 KB Output is correct
12 Correct 84 ms 8076 KB Output is correct
13 Correct 73 ms 8068 KB Output is correct
14 Correct 78 ms 8076 KB Output is correct
15 Correct 74 ms 8072 KB Output is correct
16 Correct 81 ms 8088 KB Output is correct
17 Correct 73 ms 8084 KB Output is correct
18 Correct 82 ms 8072 KB Output is correct
19 Correct 69 ms 8084 KB Output is correct
20 Correct 77 ms 8076 KB Output is correct
21 Correct 85 ms 8088 KB Output is correct
22 Correct 87 ms 7996 KB Output is correct
23 Correct 89 ms 7992 KB Output is correct
24 Correct 78 ms 7988 KB Output is correct
25 Correct 81 ms 7992 KB Output is correct
26 Correct 82 ms 7988 KB Output is correct
27 Correct 74 ms 7996 KB Output is correct
28 Correct 78 ms 8088 KB Output is correct
29 Correct 79 ms 7984 KB Output is correct
30 Correct 84 ms 8000 KB Output is correct
31 Correct 94 ms 7988 KB Output is correct
32 Correct 78 ms 7992 KB Output is correct
33 Correct 77 ms 7988 KB Output is correct
34 Correct 77 ms 7988 KB Output is correct
35 Correct 102 ms 8020 KB Output is correct
36 Correct 72 ms 7988 KB Output is correct
37 Correct 77 ms 7988 KB Output is correct
38 Correct 80 ms 8028 KB Output is correct
39 Correct 81 ms 7980 KB Output is correct
40 Correct 77 ms 8032 KB Output is correct
41 Correct 78 ms 7996 KB Output is correct
42 Correct 76 ms 7984 KB Output is correct
43 Correct 92 ms 7964 KB Output is correct
44 Correct 95 ms 8024 KB Output is correct
45 Correct 95 ms 7972 KB Output is correct
46 Correct 95 ms 8140 KB Output is correct
47 Correct 96 ms 8040 KB Output is correct
48 Correct 91 ms 7968 KB Output is correct
49 Correct 94 ms 8012 KB Output is correct
50 Correct 93 ms 7976 KB Output is correct
51 Correct 90 ms 7960 KB Output is correct
52 Correct 91 ms 8088 KB Output is correct
53 Correct 98 ms 8024 KB Output is correct
54 Correct 97 ms 8036 KB Output is correct
55 Correct 90 ms 8016 KB Output is correct
56 Correct 96 ms 8028 KB Output is correct
57 Correct 101 ms 8080 KB Output is correct
58 Correct 86 ms 7956 KB Output is correct
59 Correct 103 ms 7960 KB Output is correct
60 Correct 93 ms 7968 KB Output is correct
61 Correct 100 ms 8016 KB Output is correct
62 Correct 91 ms 7956 KB Output is correct
63 Correct 92 ms 7960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 7376 KB Output is correct
2 Correct 83 ms 8116 KB Output is correct
3 Correct 86 ms 8104 KB Output is correct
4 Correct 75 ms 8232 KB Output is correct
5 Correct 77 ms 8076 KB Output is correct
6 Correct 82 ms 8088 KB Output is correct
7 Correct 80 ms 8080 KB Output is correct
8 Correct 78 ms 8092 KB Output is correct
9 Correct 91 ms 8084 KB Output is correct
10 Correct 81 ms 8076 KB Output is correct
11 Correct 80 ms 8080 KB Output is correct
12 Correct 84 ms 8076 KB Output is correct
13 Correct 73 ms 8068 KB Output is correct
14 Correct 78 ms 8076 KB Output is correct
15 Correct 74 ms 8072 KB Output is correct
16 Correct 81 ms 8088 KB Output is correct
17 Correct 73 ms 8084 KB Output is correct
18 Correct 82 ms 8072 KB Output is correct
19 Correct 69 ms 8084 KB Output is correct
20 Correct 77 ms 8076 KB Output is correct
21 Correct 85 ms 8088 KB Output is correct
22 Correct 87 ms 7996 KB Output is correct
23 Correct 89 ms 7992 KB Output is correct
24 Correct 78 ms 7988 KB Output is correct
25 Correct 81 ms 7992 KB Output is correct
26 Correct 82 ms 7988 KB Output is correct
27 Correct 74 ms 7996 KB Output is correct
28 Correct 78 ms 8088 KB Output is correct
29 Correct 79 ms 7984 KB Output is correct
30 Correct 84 ms 8000 KB Output is correct
31 Correct 94 ms 7988 KB Output is correct
32 Correct 78 ms 7992 KB Output is correct
33 Correct 77 ms 7988 KB Output is correct
34 Correct 77 ms 7988 KB Output is correct
35 Correct 102 ms 8020 KB Output is correct
36 Correct 72 ms 7988 KB Output is correct
37 Correct 77 ms 7988 KB Output is correct
38 Correct 80 ms 8028 KB Output is correct
39 Correct 81 ms 7980 KB Output is correct
40 Correct 77 ms 8032 KB Output is correct
41 Correct 78 ms 7996 KB Output is correct
42 Correct 76 ms 7984 KB Output is correct
43 Correct 92 ms 7964 KB Output is correct
44 Correct 95 ms 8024 KB Output is correct
45 Correct 95 ms 7972 KB Output is correct
46 Correct 95 ms 8140 KB Output is correct
47 Correct 96 ms 8040 KB Output is correct
48 Correct 91 ms 7968 KB Output is correct
49 Correct 94 ms 8012 KB Output is correct
50 Correct 93 ms 7976 KB Output is correct
51 Correct 90 ms 7960 KB Output is correct
52 Correct 91 ms 8088 KB Output is correct
53 Correct 98 ms 8024 KB Output is correct
54 Correct 97 ms 8036 KB Output is correct
55 Correct 90 ms 8016 KB Output is correct
56 Correct 96 ms 8028 KB Output is correct
57 Correct 101 ms 8080 KB Output is correct
58 Correct 86 ms 7956 KB Output is correct
59 Correct 103 ms 7960 KB Output is correct
60 Correct 93 ms 7968 KB Output is correct
61 Correct 100 ms 8016 KB Output is correct
62 Correct 91 ms 7956 KB Output is correct
63 Correct 92 ms 7960 KB Output is correct
64 Correct 206 ms 8028 KB Output is correct
65 Correct 199 ms 7956 KB Output is correct
66 Correct 204 ms 7956 KB Output is correct
67 Correct 199 ms 7948 KB Output is correct
68 Correct 216 ms 8084 KB Output is correct
69 Correct 205 ms 7952 KB Output is correct
70 Correct 198 ms 8028 KB Output is correct
71 Correct 215 ms 8028 KB Output is correct
72 Correct 197 ms 7964 KB Output is correct
73 Correct 194 ms 8032 KB Output is correct
74 Correct 227 ms 8028 KB Output is correct
75 Correct 207 ms 7956 KB Output is correct
76 Correct 195 ms 8028 KB Output is correct
77 Correct 192 ms 7948 KB Output is correct
78 Correct 218 ms 8080 KB Output is correct
79 Correct 199 ms 8024 KB Output is correct
80 Correct 192 ms 7952 KB Output is correct
81 Correct 216 ms 8132 KB Output is correct
82 Correct 199 ms 8032 KB Output is correct
83 Correct 191 ms 8028 KB Output is correct
84 Correct 201 ms 8028 KB Output is correct