Submission #742529

# Submission time Handle Problem Language Result Execution time Memory
742529 2023-05-16T11:54:06 Z Stickfish Cubeword (CEOI19_cubeword) C++17
100 / 100
226 ms 10472 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cassert>
using namespace std;
using ll = long long;

const int MAXV = 63;
const ll MOD = 998244353;
ll f[MAXV][MAXV];
ll cnt_repeat[8];
ll dp[MAXV][MAXV][MAXV];

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

void get_edg(vector<string> v) {
    for (int p = 0; p < MAXV; ++p) {
        for (int q = 0; q < MAXV; ++q) {
            f[p][q] = 0;
        }
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for (size_t i = 0; i < v.size(); ++i) {
        int p = to_int(v[i][0]);
        int q = to_int(v[i].back());
        ++f[p][q];
    }
}

void get_dp() {
    for (int a = 0; a < MAXV; ++a) for (int b = 0; b <= a; ++b) for (int c = 0; c <= b; ++c) {
        dp[a][b][c] = 0;
        for (int x = 0; x < MAXV; ++x) {
            dp[a][b][c] += 1ll * f[a][x] * f[b][x] * f[c][x];
            dp[a][b][c] %= MOD;
        }
    }
}

ll get_ans() {
    ll ans = 0;
    get_dp();
    for (int a = 0; a < MAXV; ++a) for (int b = 0; b <= a; ++b) for (int c = 0; c <= b; ++c) for (int d = 0; d <= c; ++d) {
        int rpat = int(a > b) + int(b > c) * 2 + int(c > d) * 4;
        ans += dp[a][b][c] * dp[a][b][d] % MOD * dp[a][c][d] % MOD * dp[b][c][d] % MOD * cnt_repeat[rpat];
        ans %= MOD;
    }
    return ans;
}

signed main() {
    cnt_repeat[0] = 1;
    cnt_repeat[1] = 4;
    cnt_repeat[2] = 6;
    cnt_repeat[3] = 12;
    cnt_repeat[4] = 4;
    cnt_repeat[5] = 12;
    cnt_repeat[6] = 12;
    cnt_repeat[7] = 24;
    int n;
    cin >> n;
    vector<vector<string>> vals(11);
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        vals[s.size()].push_back(s);
        reverse(s.begin(), s.end());
        vals[s.size()].push_back(s);
    }
    ll ans = 0;
    for (int t = 0; t < 11; ++t) {
        if (vals[t].empty())
            continue;
        get_edg(vals[t]);
        ans += get_ans();
    }
    ans %= MOD;
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 218 ms 10356 KB Output is correct
2 Correct 208 ms 10360 KB Output is correct
3 Correct 202 ms 10368 KB Output is correct
4 Correct 194 ms 10368 KB Output is correct
5 Correct 202 ms 10472 KB Output is correct
6 Correct 210 ms 10448 KB Output is correct
7 Correct 214 ms 10356 KB Output is correct
8 Correct 205 ms 10232 KB Output is correct
9 Correct 197 ms 10368 KB Output is correct
10 Correct 209 ms 10332 KB Output is correct
11 Correct 200 ms 10432 KB Output is correct
12 Correct 226 ms 10388 KB Output is correct
13 Correct 193 ms 10348 KB Output is correct
14 Correct 210 ms 10424 KB Output is correct
15 Correct 210 ms 10384 KB Output is correct
16 Correct 194 ms 10460 KB Output is correct
17 Correct 202 ms 10324 KB Output is correct
18 Correct 203 ms 10320 KB Output is correct
19 Correct 198 ms 10460 KB Output is correct
20 Correct 210 ms 10324 KB Output is correct
21 Correct 199 ms 10228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 218 ms 10356 KB Output is correct
2 Correct 208 ms 10360 KB Output is correct
3 Correct 202 ms 10368 KB Output is correct
4 Correct 194 ms 10368 KB Output is correct
5 Correct 202 ms 10472 KB Output is correct
6 Correct 210 ms 10448 KB Output is correct
7 Correct 214 ms 10356 KB Output is correct
8 Correct 205 ms 10232 KB Output is correct
9 Correct 197 ms 10368 KB Output is correct
10 Correct 209 ms 10332 KB Output is correct
11 Correct 200 ms 10432 KB Output is correct
12 Correct 226 ms 10388 KB Output is correct
13 Correct 193 ms 10348 KB Output is correct
14 Correct 210 ms 10424 KB Output is correct
15 Correct 210 ms 10384 KB Output is correct
16 Correct 194 ms 10460 KB Output is correct
17 Correct 202 ms 10324 KB Output is correct
18 Correct 203 ms 10320 KB Output is correct
19 Correct 198 ms 10460 KB Output is correct
20 Correct 210 ms 10324 KB Output is correct
21 Correct 199 ms 10228 KB Output is correct
22 Correct 205 ms 9212 KB Output is correct
23 Correct 208 ms 9068 KB Output is correct
24 Correct 210 ms 9088 KB Output is correct
25 Correct 205 ms 9000 KB Output is correct
26 Correct 205 ms 9156 KB Output is correct
27 Correct 199 ms 8964 KB Output is correct
28 Correct 206 ms 9032 KB Output is correct
29 Correct 194 ms 9028 KB Output is correct
30 Correct 193 ms 9064 KB Output is correct
31 Correct 195 ms 9240 KB Output is correct
32 Correct 219 ms 9052 KB Output is correct
33 Correct 194 ms 9040 KB Output is correct
34 Correct 191 ms 9084 KB Output is correct
35 Correct 196 ms 9092 KB Output is correct
36 Correct 197 ms 8864 KB Output is correct
37 Correct 203 ms 9076 KB Output is correct
38 Correct 189 ms 9060 KB Output is correct
39 Correct 191 ms 9000 KB Output is correct
40 Correct 199 ms 8924 KB Output is correct
41 Correct 196 ms 9224 KB Output is correct
42 Correct 192 ms 9072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 218 ms 10356 KB Output is correct
2 Correct 208 ms 10360 KB Output is correct
3 Correct 202 ms 10368 KB Output is correct
4 Correct 194 ms 10368 KB Output is correct
5 Correct 202 ms 10472 KB Output is correct
6 Correct 210 ms 10448 KB Output is correct
7 Correct 214 ms 10356 KB Output is correct
8 Correct 205 ms 10232 KB Output is correct
9 Correct 197 ms 10368 KB Output is correct
10 Correct 209 ms 10332 KB Output is correct
11 Correct 200 ms 10432 KB Output is correct
12 Correct 226 ms 10388 KB Output is correct
13 Correct 193 ms 10348 KB Output is correct
14 Correct 210 ms 10424 KB Output is correct
15 Correct 210 ms 10384 KB Output is correct
16 Correct 194 ms 10460 KB Output is correct
17 Correct 202 ms 10324 KB Output is correct
18 Correct 203 ms 10320 KB Output is correct
19 Correct 198 ms 10460 KB Output is correct
20 Correct 210 ms 10324 KB Output is correct
21 Correct 199 ms 10228 KB Output is correct
22 Correct 205 ms 9212 KB Output is correct
23 Correct 208 ms 9068 KB Output is correct
24 Correct 210 ms 9088 KB Output is correct
25 Correct 205 ms 9000 KB Output is correct
26 Correct 205 ms 9156 KB Output is correct
27 Correct 199 ms 8964 KB Output is correct
28 Correct 206 ms 9032 KB Output is correct
29 Correct 194 ms 9028 KB Output is correct
30 Correct 193 ms 9064 KB Output is correct
31 Correct 195 ms 9240 KB Output is correct
32 Correct 219 ms 9052 KB Output is correct
33 Correct 194 ms 9040 KB Output is correct
34 Correct 191 ms 9084 KB Output is correct
35 Correct 196 ms 9092 KB Output is correct
36 Correct 197 ms 8864 KB Output is correct
37 Correct 203 ms 9076 KB Output is correct
38 Correct 189 ms 9060 KB Output is correct
39 Correct 191 ms 9000 KB Output is correct
40 Correct 199 ms 8924 KB Output is correct
41 Correct 196 ms 9224 KB Output is correct
42 Correct 192 ms 9072 KB Output is correct
43 Correct 199 ms 8676 KB Output is correct
44 Correct 191 ms 9476 KB Output is correct
45 Correct 207 ms 9476 KB Output is correct
46 Correct 197 ms 9488 KB Output is correct
47 Correct 191 ms 9404 KB Output is correct
48 Correct 196 ms 9488 KB Output is correct
49 Correct 190 ms 9896 KB Output is correct
50 Correct 208 ms 9852 KB Output is correct
51 Correct 201 ms 9688 KB Output is correct
52 Correct 199 ms 9544 KB Output is correct
53 Correct 197 ms 9444 KB Output is correct
54 Correct 194 ms 9496 KB Output is correct
55 Correct 191 ms 9416 KB Output is correct
56 Correct 203 ms 9536 KB Output is correct
57 Correct 199 ms 9516 KB Output is correct
58 Correct 202 ms 9412 KB Output is correct
59 Correct 200 ms 9700 KB Output is correct
60 Correct 195 ms 9904 KB Output is correct
61 Correct 197 ms 9508 KB Output is correct
62 Correct 206 ms 9688 KB Output is correct
63 Correct 199 ms 9444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 218 ms 10356 KB Output is correct
2 Correct 208 ms 10360 KB Output is correct
3 Correct 202 ms 10368 KB Output is correct
4 Correct 194 ms 10368 KB Output is correct
5 Correct 202 ms 10472 KB Output is correct
6 Correct 210 ms 10448 KB Output is correct
7 Correct 214 ms 10356 KB Output is correct
8 Correct 205 ms 10232 KB Output is correct
9 Correct 197 ms 10368 KB Output is correct
10 Correct 209 ms 10332 KB Output is correct
11 Correct 200 ms 10432 KB Output is correct
12 Correct 226 ms 10388 KB Output is correct
13 Correct 193 ms 10348 KB Output is correct
14 Correct 210 ms 10424 KB Output is correct
15 Correct 210 ms 10384 KB Output is correct
16 Correct 194 ms 10460 KB Output is correct
17 Correct 202 ms 10324 KB Output is correct
18 Correct 203 ms 10320 KB Output is correct
19 Correct 198 ms 10460 KB Output is correct
20 Correct 210 ms 10324 KB Output is correct
21 Correct 199 ms 10228 KB Output is correct
22 Correct 205 ms 9212 KB Output is correct
23 Correct 208 ms 9068 KB Output is correct
24 Correct 210 ms 9088 KB Output is correct
25 Correct 205 ms 9000 KB Output is correct
26 Correct 205 ms 9156 KB Output is correct
27 Correct 199 ms 8964 KB Output is correct
28 Correct 206 ms 9032 KB Output is correct
29 Correct 194 ms 9028 KB Output is correct
30 Correct 193 ms 9064 KB Output is correct
31 Correct 195 ms 9240 KB Output is correct
32 Correct 219 ms 9052 KB Output is correct
33 Correct 194 ms 9040 KB Output is correct
34 Correct 191 ms 9084 KB Output is correct
35 Correct 196 ms 9092 KB Output is correct
36 Correct 197 ms 8864 KB Output is correct
37 Correct 203 ms 9076 KB Output is correct
38 Correct 189 ms 9060 KB Output is correct
39 Correct 191 ms 9000 KB Output is correct
40 Correct 199 ms 8924 KB Output is correct
41 Correct 196 ms 9224 KB Output is correct
42 Correct 192 ms 9072 KB Output is correct
43 Correct 199 ms 8676 KB Output is correct
44 Correct 191 ms 9476 KB Output is correct
45 Correct 207 ms 9476 KB Output is correct
46 Correct 197 ms 9488 KB Output is correct
47 Correct 191 ms 9404 KB Output is correct
48 Correct 196 ms 9488 KB Output is correct
49 Correct 190 ms 9896 KB Output is correct
50 Correct 208 ms 9852 KB Output is correct
51 Correct 201 ms 9688 KB Output is correct
52 Correct 199 ms 9544 KB Output is correct
53 Correct 197 ms 9444 KB Output is correct
54 Correct 194 ms 9496 KB Output is correct
55 Correct 191 ms 9416 KB Output is correct
56 Correct 203 ms 9536 KB Output is correct
57 Correct 199 ms 9516 KB Output is correct
58 Correct 202 ms 9412 KB Output is correct
59 Correct 200 ms 9700 KB Output is correct
60 Correct 195 ms 9904 KB Output is correct
61 Correct 197 ms 9508 KB Output is correct
62 Correct 206 ms 9688 KB Output is correct
63 Correct 199 ms 9444 KB Output is correct
64 Correct 193 ms 9496 KB Output is correct
65 Correct 196 ms 9400 KB Output is correct
66 Correct 192 ms 9408 KB Output is correct
67 Correct 203 ms 9660 KB Output is correct
68 Correct 190 ms 9408 KB Output is correct
69 Correct 187 ms 9784 KB Output is correct
70 Correct 218 ms 9496 KB Output is correct
71 Correct 196 ms 9368 KB Output is correct
72 Correct 191 ms 9456 KB Output is correct
73 Correct 193 ms 9428 KB Output is correct
74 Correct 201 ms 9780 KB Output is correct
75 Correct 197 ms 9744 KB Output is correct
76 Correct 202 ms 9680 KB Output is correct
77 Correct 192 ms 9584 KB Output is correct
78 Correct 191 ms 9492 KB Output is correct
79 Correct 189 ms 9416 KB Output is correct
80 Correct 202 ms 9848 KB Output is correct
81 Correct 211 ms 9708 KB Output is correct
82 Correct 207 ms 9684 KB Output is correct
83 Correct 196 ms 9852 KB Output is correct
84 Correct 189 ms 9796 KB Output is correct