Submission #703954

# Submission time Handle Problem Language Result Execution time Memory
703954 2023-03-01T06:01:16 Z LittleCube Cubeword (CEOI19_cubeword) C++17
84 / 100
1100 ms 9832 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
using namespace std;

const int C = 62;
const ll mod = 998'244'353;
int N;
vector<string> v[11];
ll ans, way[C][C][C], edge[C][C];

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

signed main()
{
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        string s;
        cin >> s;
        v[s.size()].emplace_back(s);
        reverse(s.begin(), s.end());
        v[s.size()].emplace_back(s);
    }
    for (int s = 3; s <= 10; s++)
    {
        sort(v[s].begin(), v[s].end());
        v[s].resize(unique(v[s].begin(), v[s].end()) - v[s].begin());
        for (int i = 0; i < C; i++)
            for (int j = 0; j < C; j++)
                for (int k = 0; k < C; k++)
                    way[i][j][k] = edge[i][j] = 0;
        for (auto t : v[s])
            edge[id(t.front())][id(t.back())]++;
        for (int i = 0; i < C; i++)
            for (int j = 0; j < C; j++)
                for (int k = 0; k < C; k++)
                    for (int l = 0; l < C; l++)
                        way[i][j][k] = (way[i][j][k] + edge[l][i] * edge[l][j] % mod * edge[l][k]) % mod;

        for (int i = 0; i < C; i++)
            for (int j = 0; j < C; j++)
                for (int k = 0; k < C; k++)
                    for (int l = 0; l < C; l++)
                        ans = (ans + way[i][j][k] * way[i][j][l] % mod * way[i][k][l] % mod * way[j][k][l]) % mod;
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1071 ms 9684 KB Output is correct
2 Correct 1061 ms 9792 KB Output is correct
3 Correct 1064 ms 9812 KB Output is correct
4 Correct 1062 ms 9748 KB Output is correct
5 Correct 1070 ms 9684 KB Output is correct
6 Correct 1063 ms 9832 KB Output is correct
7 Correct 1066 ms 9808 KB Output is correct
8 Correct 1091 ms 9600 KB Output is correct
9 Correct 1083 ms 9724 KB Output is correct
10 Correct 1063 ms 9748 KB Output is correct
11 Correct 1064 ms 9804 KB Output is correct
12 Correct 1066 ms 9720 KB Output is correct
13 Correct 1058 ms 9724 KB Output is correct
14 Correct 1064 ms 9636 KB Output is correct
15 Correct 1075 ms 9704 KB Output is correct
16 Correct 1071 ms 9796 KB Output is correct
17 Correct 1068 ms 9732 KB Output is correct
18 Correct 1072 ms 9680 KB Output is correct
19 Correct 1054 ms 9688 KB Output is correct
20 Correct 1058 ms 9684 KB Output is correct
21 Correct 1059 ms 9620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1071 ms 9684 KB Output is correct
2 Correct 1061 ms 9792 KB Output is correct
3 Correct 1064 ms 9812 KB Output is correct
4 Correct 1062 ms 9748 KB Output is correct
5 Correct 1070 ms 9684 KB Output is correct
6 Correct 1063 ms 9832 KB Output is correct
7 Correct 1066 ms 9808 KB Output is correct
8 Correct 1091 ms 9600 KB Output is correct
9 Correct 1083 ms 9724 KB Output is correct
10 Correct 1063 ms 9748 KB Output is correct
11 Correct 1064 ms 9804 KB Output is correct
12 Correct 1066 ms 9720 KB Output is correct
13 Correct 1058 ms 9724 KB Output is correct
14 Correct 1064 ms 9636 KB Output is correct
15 Correct 1075 ms 9704 KB Output is correct
16 Correct 1071 ms 9796 KB Output is correct
17 Correct 1068 ms 9732 KB Output is correct
18 Correct 1072 ms 9680 KB Output is correct
19 Correct 1054 ms 9688 KB Output is correct
20 Correct 1058 ms 9684 KB Output is correct
21 Correct 1059 ms 9620 KB Output is correct
22 Correct 1068 ms 9384 KB Output is correct
23 Correct 1058 ms 9388 KB Output is correct
24 Correct 1052 ms 9592 KB Output is correct
25 Correct 1055 ms 9600 KB Output is correct
26 Correct 1059 ms 9372 KB Output is correct
27 Correct 1059 ms 9724 KB Output is correct
28 Correct 1057 ms 9432 KB Output is correct
29 Correct 1068 ms 9468 KB Output is correct
30 Correct 1052 ms 9380 KB Output is correct
31 Correct 1065 ms 9676 KB Output is correct
32 Correct 1056 ms 9424 KB Output is correct
33 Correct 1055 ms 9412 KB Output is correct
34 Correct 1063 ms 9504 KB Output is correct
35 Correct 1064 ms 9580 KB Output is correct
36 Correct 1060 ms 9592 KB Output is correct
37 Correct 1059 ms 9312 KB Output is correct
38 Correct 1090 ms 9724 KB Output is correct
39 Correct 1063 ms 9532 KB Output is correct
40 Correct 1072 ms 9572 KB Output is correct
41 Correct 1091 ms 9540 KB Output is correct
42 Correct 1063 ms 9436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1071 ms 9684 KB Output is correct
2 Correct 1061 ms 9792 KB Output is correct
3 Correct 1064 ms 9812 KB Output is correct
4 Correct 1062 ms 9748 KB Output is correct
5 Correct 1070 ms 9684 KB Output is correct
6 Correct 1063 ms 9832 KB Output is correct
7 Correct 1066 ms 9808 KB Output is correct
8 Correct 1091 ms 9600 KB Output is correct
9 Correct 1083 ms 9724 KB Output is correct
10 Correct 1063 ms 9748 KB Output is correct
11 Correct 1064 ms 9804 KB Output is correct
12 Correct 1066 ms 9720 KB Output is correct
13 Correct 1058 ms 9724 KB Output is correct
14 Correct 1064 ms 9636 KB Output is correct
15 Correct 1075 ms 9704 KB Output is correct
16 Correct 1071 ms 9796 KB Output is correct
17 Correct 1068 ms 9732 KB Output is correct
18 Correct 1072 ms 9680 KB Output is correct
19 Correct 1054 ms 9688 KB Output is correct
20 Correct 1058 ms 9684 KB Output is correct
21 Correct 1059 ms 9620 KB Output is correct
22 Correct 1068 ms 9384 KB Output is correct
23 Correct 1058 ms 9388 KB Output is correct
24 Correct 1052 ms 9592 KB Output is correct
25 Correct 1055 ms 9600 KB Output is correct
26 Correct 1059 ms 9372 KB Output is correct
27 Correct 1059 ms 9724 KB Output is correct
28 Correct 1057 ms 9432 KB Output is correct
29 Correct 1068 ms 9468 KB Output is correct
30 Correct 1052 ms 9380 KB Output is correct
31 Correct 1065 ms 9676 KB Output is correct
32 Correct 1056 ms 9424 KB Output is correct
33 Correct 1055 ms 9412 KB Output is correct
34 Correct 1063 ms 9504 KB Output is correct
35 Correct 1064 ms 9580 KB Output is correct
36 Correct 1060 ms 9592 KB Output is correct
37 Correct 1059 ms 9312 KB Output is correct
38 Correct 1090 ms 9724 KB Output is correct
39 Correct 1063 ms 9532 KB Output is correct
40 Correct 1072 ms 9572 KB Output is correct
41 Correct 1091 ms 9540 KB Output is correct
42 Correct 1063 ms 9436 KB Output is correct
43 Correct 1063 ms 9344 KB Output is correct
44 Correct 1074 ms 9360 KB Output is correct
45 Correct 1063 ms 9352 KB Output is correct
46 Correct 1059 ms 9348 KB Output is correct
47 Correct 1062 ms 9304 KB Output is correct
48 Correct 1077 ms 9328 KB Output is correct
49 Correct 1065 ms 9700 KB Output is correct
50 Correct 1059 ms 9744 KB Output is correct
51 Correct 1059 ms 9596 KB Output is correct
52 Correct 1073 ms 9356 KB Output is correct
53 Correct 1066 ms 9344 KB Output is correct
54 Correct 1089 ms 9352 KB Output is correct
55 Correct 1074 ms 9320 KB Output is correct
56 Correct 1060 ms 9356 KB Output is correct
57 Correct 1072 ms 9352 KB Output is correct
58 Correct 1074 ms 9344 KB Output is correct
59 Correct 1060 ms 9676 KB Output is correct
60 Correct 1071 ms 9708 KB Output is correct
61 Correct 1059 ms 9464 KB Output is correct
62 Correct 1059 ms 9552 KB Output is correct
63 Correct 1060 ms 9352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1071 ms 9684 KB Output is correct
2 Correct 1061 ms 9792 KB Output is correct
3 Correct 1064 ms 9812 KB Output is correct
4 Correct 1062 ms 9748 KB Output is correct
5 Correct 1070 ms 9684 KB Output is correct
6 Correct 1063 ms 9832 KB Output is correct
7 Correct 1066 ms 9808 KB Output is correct
8 Correct 1091 ms 9600 KB Output is correct
9 Correct 1083 ms 9724 KB Output is correct
10 Correct 1063 ms 9748 KB Output is correct
11 Correct 1064 ms 9804 KB Output is correct
12 Correct 1066 ms 9720 KB Output is correct
13 Correct 1058 ms 9724 KB Output is correct
14 Correct 1064 ms 9636 KB Output is correct
15 Correct 1075 ms 9704 KB Output is correct
16 Correct 1071 ms 9796 KB Output is correct
17 Correct 1068 ms 9732 KB Output is correct
18 Correct 1072 ms 9680 KB Output is correct
19 Correct 1054 ms 9688 KB Output is correct
20 Correct 1058 ms 9684 KB Output is correct
21 Correct 1059 ms 9620 KB Output is correct
22 Correct 1068 ms 9384 KB Output is correct
23 Correct 1058 ms 9388 KB Output is correct
24 Correct 1052 ms 9592 KB Output is correct
25 Correct 1055 ms 9600 KB Output is correct
26 Correct 1059 ms 9372 KB Output is correct
27 Correct 1059 ms 9724 KB Output is correct
28 Correct 1057 ms 9432 KB Output is correct
29 Correct 1068 ms 9468 KB Output is correct
30 Correct 1052 ms 9380 KB Output is correct
31 Correct 1065 ms 9676 KB Output is correct
32 Correct 1056 ms 9424 KB Output is correct
33 Correct 1055 ms 9412 KB Output is correct
34 Correct 1063 ms 9504 KB Output is correct
35 Correct 1064 ms 9580 KB Output is correct
36 Correct 1060 ms 9592 KB Output is correct
37 Correct 1059 ms 9312 KB Output is correct
38 Correct 1090 ms 9724 KB Output is correct
39 Correct 1063 ms 9532 KB Output is correct
40 Correct 1072 ms 9572 KB Output is correct
41 Correct 1091 ms 9540 KB Output is correct
42 Correct 1063 ms 9436 KB Output is correct
43 Correct 1063 ms 9344 KB Output is correct
44 Correct 1074 ms 9360 KB Output is correct
45 Correct 1063 ms 9352 KB Output is correct
46 Correct 1059 ms 9348 KB Output is correct
47 Correct 1062 ms 9304 KB Output is correct
48 Correct 1077 ms 9328 KB Output is correct
49 Correct 1065 ms 9700 KB Output is correct
50 Correct 1059 ms 9744 KB Output is correct
51 Correct 1059 ms 9596 KB Output is correct
52 Correct 1073 ms 9356 KB Output is correct
53 Correct 1066 ms 9344 KB Output is correct
54 Correct 1089 ms 9352 KB Output is correct
55 Correct 1074 ms 9320 KB Output is correct
56 Correct 1060 ms 9356 KB Output is correct
57 Correct 1072 ms 9352 KB Output is correct
58 Correct 1074 ms 9344 KB Output is correct
59 Correct 1060 ms 9676 KB Output is correct
60 Correct 1071 ms 9708 KB Output is correct
61 Correct 1059 ms 9464 KB Output is correct
62 Correct 1059 ms 9552 KB Output is correct
63 Correct 1060 ms 9352 KB Output is correct
64 Correct 1058 ms 9284 KB Output is correct
65 Correct 1058 ms 9232 KB Output is correct
66 Correct 1053 ms 9272 KB Output is correct
67 Correct 1055 ms 9580 KB Output is correct
68 Correct 1071 ms 9280 KB Output is correct
69 Correct 1098 ms 9696 KB Output is correct
70 Correct 1100 ms 9352 KB Output is correct
71 Correct 1092 ms 9340 KB Output is correct
72 Execution timed out 1151 ms 9348 KB Time limit exceeded
73 Halted 0 ms 0 KB -