Submission #696109

# Submission time Handle Problem Language Result Execution time Memory
696109 2023-02-05T13:34:09 Z sugartheanh Cubeword (CEOI19_cubeword) C++14
100 / 100
275 ms 22348 KB
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

constexpr int M = 62;
constexpr int L = 8;
constexpr int MOD = 998244353;

typedef long long ll;

int Q[L][M][M];
int DP[L][M][M][M];


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

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

    int N; cin >> N;
    set<string> W;
    for (int i = 0; i < N; i++) {
        string S; cin >> S;
        W.insert(S);
        reverse(S.begin(),S.end());
        W.insert(S);
    }

    for (const string&w: W) {
        Q[w.size()-3][id(w[0])][id(w.back())]++;
    }

    for (int s = 0; s < L; s++) {
        for (int i = 0; i < M; i++) {
            for (int j = i; j < M; j++) {
                for (int k = j; k < M; k++) {
                    for (int l = 0; l < M; l++) {
                        DP[s][i][j][k] += ( (ll)Q[s][i][l] * (ll)Q[s][j][l] * (ll)Q[s][k][l] ) % MOD;
                        if (DP[s][i][j][k] >= MOD) DP[s][i][j][k] -= MOD;
                    }
                }
            }
        }
    }

    vector<int> Mul{24, 12, 12, 4, 12, 6, 4, 1};
    ll ans = 0;
    for (int s = 0; s < L; s++) {
        for (int i = 0; i < M; i++) {
            for (int j = i; j < M; j++) {
                for (int k = j; k < M; k++) {
                    for (int l = k; l < M; l++) {
                        int q = (i==j)<<2 | (j==k)<<1 | (k==l);
                        ans += ((ll)DP[s][i][j][k] * (ll)DP[s][i][j][l] % MOD) * ((ll)DP[s][i][k][l] * (ll)DP[s][j][k][l] % MOD) % MOD * Mul[q]; 
                    }
                }
            }
        }
    }
    cout << ans % MOD << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 231 ms 21100 KB Output is correct
2 Correct 213 ms 21212 KB Output is correct
3 Correct 218 ms 21040 KB Output is correct
4 Correct 231 ms 21224 KB Output is correct
5 Correct 222 ms 21056 KB Output is correct
6 Correct 215 ms 21004 KB Output is correct
7 Correct 222 ms 21272 KB Output is correct
8 Correct 230 ms 21132 KB Output is correct
9 Correct 234 ms 21036 KB Output is correct
10 Correct 229 ms 21132 KB Output is correct
11 Correct 231 ms 21120 KB Output is correct
12 Correct 266 ms 21112 KB Output is correct
13 Correct 237 ms 21132 KB Output is correct
14 Correct 208 ms 21012 KB Output is correct
15 Correct 226 ms 21124 KB Output is correct
16 Correct 222 ms 21004 KB Output is correct
17 Correct 235 ms 21096 KB Output is correct
18 Correct 232 ms 21116 KB Output is correct
19 Correct 217 ms 21092 KB Output is correct
20 Correct 211 ms 21156 KB Output is correct
21 Correct 260 ms 21112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 231 ms 21100 KB Output is correct
2 Correct 213 ms 21212 KB Output is correct
3 Correct 218 ms 21040 KB Output is correct
4 Correct 231 ms 21224 KB Output is correct
5 Correct 222 ms 21056 KB Output is correct
6 Correct 215 ms 21004 KB Output is correct
7 Correct 222 ms 21272 KB Output is correct
8 Correct 230 ms 21132 KB Output is correct
9 Correct 234 ms 21036 KB Output is correct
10 Correct 229 ms 21132 KB Output is correct
11 Correct 231 ms 21120 KB Output is correct
12 Correct 266 ms 21112 KB Output is correct
13 Correct 237 ms 21132 KB Output is correct
14 Correct 208 ms 21012 KB Output is correct
15 Correct 226 ms 21124 KB Output is correct
16 Correct 222 ms 21004 KB Output is correct
17 Correct 235 ms 21096 KB Output is correct
18 Correct 232 ms 21116 KB Output is correct
19 Correct 217 ms 21092 KB Output is correct
20 Correct 211 ms 21156 KB Output is correct
21 Correct 260 ms 21112 KB Output is correct
22 Correct 213 ms 21680 KB Output is correct
23 Correct 234 ms 21712 KB Output is correct
24 Correct 256 ms 21624 KB Output is correct
25 Correct 227 ms 21648 KB Output is correct
26 Correct 225 ms 21676 KB Output is correct
27 Correct 272 ms 21724 KB Output is correct
28 Correct 249 ms 21712 KB Output is correct
29 Correct 238 ms 21660 KB Output is correct
30 Correct 240 ms 21720 KB Output is correct
31 Correct 227 ms 21592 KB Output is correct
32 Correct 233 ms 21692 KB Output is correct
33 Correct 238 ms 21700 KB Output is correct
34 Correct 261 ms 21692 KB Output is correct
35 Correct 257 ms 21712 KB Output is correct
36 Correct 227 ms 21708 KB Output is correct
37 Correct 247 ms 21708 KB Output is correct
38 Correct 240 ms 21704 KB Output is correct
39 Correct 222 ms 21708 KB Output is correct
40 Correct 238 ms 21700 KB Output is correct
41 Correct 232 ms 21664 KB Output is correct
42 Correct 227 ms 21756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 231 ms 21100 KB Output is correct
2 Correct 213 ms 21212 KB Output is correct
3 Correct 218 ms 21040 KB Output is correct
4 Correct 231 ms 21224 KB Output is correct
5 Correct 222 ms 21056 KB Output is correct
6 Correct 215 ms 21004 KB Output is correct
7 Correct 222 ms 21272 KB Output is correct
8 Correct 230 ms 21132 KB Output is correct
9 Correct 234 ms 21036 KB Output is correct
10 Correct 229 ms 21132 KB Output is correct
11 Correct 231 ms 21120 KB Output is correct
12 Correct 266 ms 21112 KB Output is correct
13 Correct 237 ms 21132 KB Output is correct
14 Correct 208 ms 21012 KB Output is correct
15 Correct 226 ms 21124 KB Output is correct
16 Correct 222 ms 21004 KB Output is correct
17 Correct 235 ms 21096 KB Output is correct
18 Correct 232 ms 21116 KB Output is correct
19 Correct 217 ms 21092 KB Output is correct
20 Correct 211 ms 21156 KB Output is correct
21 Correct 260 ms 21112 KB Output is correct
22 Correct 213 ms 21680 KB Output is correct
23 Correct 234 ms 21712 KB Output is correct
24 Correct 256 ms 21624 KB Output is correct
25 Correct 227 ms 21648 KB Output is correct
26 Correct 225 ms 21676 KB Output is correct
27 Correct 272 ms 21724 KB Output is correct
28 Correct 249 ms 21712 KB Output is correct
29 Correct 238 ms 21660 KB Output is correct
30 Correct 240 ms 21720 KB Output is correct
31 Correct 227 ms 21592 KB Output is correct
32 Correct 233 ms 21692 KB Output is correct
33 Correct 238 ms 21700 KB Output is correct
34 Correct 261 ms 21692 KB Output is correct
35 Correct 257 ms 21712 KB Output is correct
36 Correct 227 ms 21708 KB Output is correct
37 Correct 247 ms 21708 KB Output is correct
38 Correct 240 ms 21704 KB Output is correct
39 Correct 222 ms 21708 KB Output is correct
40 Correct 238 ms 21700 KB Output is correct
41 Correct 232 ms 21664 KB Output is correct
42 Correct 227 ms 21756 KB Output is correct
43 Correct 275 ms 21956 KB Output is correct
44 Correct 247 ms 22024 KB Output is correct
45 Correct 240 ms 21940 KB Output is correct
46 Correct 270 ms 21928 KB Output is correct
47 Correct 226 ms 21892 KB Output is correct
48 Correct 232 ms 21940 KB Output is correct
49 Correct 217 ms 21896 KB Output is correct
50 Correct 220 ms 22144 KB Output is correct
51 Correct 211 ms 21848 KB Output is correct
52 Correct 217 ms 21840 KB Output is correct
53 Correct 230 ms 21960 KB Output is correct
54 Correct 220 ms 21904 KB Output is correct
55 Correct 231 ms 21892 KB Output is correct
56 Correct 253 ms 22040 KB Output is correct
57 Correct 236 ms 21924 KB Output is correct
58 Correct 237 ms 21912 KB Output is correct
59 Correct 243 ms 21880 KB Output is correct
60 Correct 213 ms 21840 KB Output is correct
61 Correct 212 ms 22036 KB Output is correct
62 Correct 231 ms 21948 KB Output is correct
63 Correct 217 ms 21840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 231 ms 21100 KB Output is correct
2 Correct 213 ms 21212 KB Output is correct
3 Correct 218 ms 21040 KB Output is correct
4 Correct 231 ms 21224 KB Output is correct
5 Correct 222 ms 21056 KB Output is correct
6 Correct 215 ms 21004 KB Output is correct
7 Correct 222 ms 21272 KB Output is correct
8 Correct 230 ms 21132 KB Output is correct
9 Correct 234 ms 21036 KB Output is correct
10 Correct 229 ms 21132 KB Output is correct
11 Correct 231 ms 21120 KB Output is correct
12 Correct 266 ms 21112 KB Output is correct
13 Correct 237 ms 21132 KB Output is correct
14 Correct 208 ms 21012 KB Output is correct
15 Correct 226 ms 21124 KB Output is correct
16 Correct 222 ms 21004 KB Output is correct
17 Correct 235 ms 21096 KB Output is correct
18 Correct 232 ms 21116 KB Output is correct
19 Correct 217 ms 21092 KB Output is correct
20 Correct 211 ms 21156 KB Output is correct
21 Correct 260 ms 21112 KB Output is correct
22 Correct 213 ms 21680 KB Output is correct
23 Correct 234 ms 21712 KB Output is correct
24 Correct 256 ms 21624 KB Output is correct
25 Correct 227 ms 21648 KB Output is correct
26 Correct 225 ms 21676 KB Output is correct
27 Correct 272 ms 21724 KB Output is correct
28 Correct 249 ms 21712 KB Output is correct
29 Correct 238 ms 21660 KB Output is correct
30 Correct 240 ms 21720 KB Output is correct
31 Correct 227 ms 21592 KB Output is correct
32 Correct 233 ms 21692 KB Output is correct
33 Correct 238 ms 21700 KB Output is correct
34 Correct 261 ms 21692 KB Output is correct
35 Correct 257 ms 21712 KB Output is correct
36 Correct 227 ms 21708 KB Output is correct
37 Correct 247 ms 21708 KB Output is correct
38 Correct 240 ms 21704 KB Output is correct
39 Correct 222 ms 21708 KB Output is correct
40 Correct 238 ms 21700 KB Output is correct
41 Correct 232 ms 21664 KB Output is correct
42 Correct 227 ms 21756 KB Output is correct
43 Correct 275 ms 21956 KB Output is correct
44 Correct 247 ms 22024 KB Output is correct
45 Correct 240 ms 21940 KB Output is correct
46 Correct 270 ms 21928 KB Output is correct
47 Correct 226 ms 21892 KB Output is correct
48 Correct 232 ms 21940 KB Output is correct
49 Correct 217 ms 21896 KB Output is correct
50 Correct 220 ms 22144 KB Output is correct
51 Correct 211 ms 21848 KB Output is correct
52 Correct 217 ms 21840 KB Output is correct
53 Correct 230 ms 21960 KB Output is correct
54 Correct 220 ms 21904 KB Output is correct
55 Correct 231 ms 21892 KB Output is correct
56 Correct 253 ms 22040 KB Output is correct
57 Correct 236 ms 21924 KB Output is correct
58 Correct 237 ms 21912 KB Output is correct
59 Correct 243 ms 21880 KB Output is correct
60 Correct 213 ms 21840 KB Output is correct
61 Correct 212 ms 22036 KB Output is correct
62 Correct 231 ms 21948 KB Output is correct
63 Correct 217 ms 21840 KB Output is correct
64 Correct 215 ms 22112 KB Output is correct
65 Correct 231 ms 22116 KB Output is correct
66 Correct 213 ms 22160 KB Output is correct
67 Correct 235 ms 22220 KB Output is correct
68 Correct 215 ms 22184 KB Output is correct
69 Correct 222 ms 22092 KB Output is correct
70 Correct 240 ms 22188 KB Output is correct
71 Correct 231 ms 22180 KB Output is correct
72 Correct 224 ms 22180 KB Output is correct
73 Correct 215 ms 22240 KB Output is correct
74 Correct 221 ms 22092 KB Output is correct
75 Correct 223 ms 22096 KB Output is correct
76 Correct 248 ms 22172 KB Output is correct
77 Correct 219 ms 22112 KB Output is correct
78 Correct 211 ms 22128 KB Output is correct
79 Correct 218 ms 22348 KB Output is correct
80 Correct 215 ms 22172 KB Output is correct
81 Correct 239 ms 22160 KB Output is correct
82 Correct 222 ms 22304 KB Output is correct
83 Correct 228 ms 22152 KB Output is correct
84 Correct 215 ms 22068 KB Output is correct