#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
constexpr ll MAXN = 1e6 + 10;
constexpr ll MAXM = 26 + 26 + 10;
constexpr ll MOD = 998244353;
inline int f(char c) {
if (c >= 'a' && c <= 'z') return c - 'a';
else if (c >= 'A' && c <= 'Z') return c - 'A' + 26;
return c - '0' + 26 + 26;
}
ll F[MAXM][MAXM], T[MAXM][MAXM][MAXM], ans;
int n, nxt[MAXN][MAXM], sz = 0;
vector<string> vec[MAXM];
inline bool add(string s) {
int v = 0;
bool flag = false;
for (char c : s) {
if (!nxt[v][f(c)]) {
flag = true;
nxt[v][f(c)] = ++sz;
}
v = nxt[v][f(c)];
}
return flag;
}
inline void solve(int len) {
memset(F, 0, sizeof F);
memset(T, 0, sizeof T);
for (int i = 0; i <= sz; i++)
memset(nxt[i], 0, sizeof nxt[i]);
sz = 0;
for (string s : vec[len])
if (add(s))
F[f(s.front())][f(s.back())]++;
for (int i = 0; i < MAXM; i++)
for (int j = 0; j < MAXM; j++)
for (int k = 0; k < MAXM; k++)
for (int a = 0; a < MAXM; a++)
T[i][j][k] = (T[i][j][k] + F[a][i] * F[a][j] * F[a][k]) % MOD;
for (int a = 0; a < MAXM; a++)
for (int b = 0; b < MAXM; b++)
for (int c = 0; c < MAXM; c++)
for (int d = 0; d < MAXM; d++)
ans = (ans + T[a][b][c] * T[a][b][d] % MOD * T[a][c][d] % MOD * T[b][c][d]) % MOD;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
vec[s.size()].push_back(s);
reverse(all(s));
vec[s.size()].push_back(s);
}
for (int i = 3; i <= 10; i++)
solve(i);
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1047 ms |
54096 KB |
Output is correct |
2 |
Correct |
1039 ms |
54100 KB |
Output is correct |
3 |
Correct |
1035 ms |
54220 KB |
Output is correct |
4 |
Correct |
1034 ms |
54444 KB |
Output is correct |
5 |
Correct |
1032 ms |
53972 KB |
Output is correct |
6 |
Correct |
1037 ms |
53480 KB |
Output is correct |
7 |
Correct |
1035 ms |
54020 KB |
Output is correct |
8 |
Correct |
1036 ms |
53760 KB |
Output is correct |
9 |
Correct |
1034 ms |
53632 KB |
Output is correct |
10 |
Correct |
1030 ms |
54040 KB |
Output is correct |
11 |
Correct |
1038 ms |
54104 KB |
Output is correct |
12 |
Correct |
1037 ms |
53880 KB |
Output is correct |
13 |
Correct |
1042 ms |
54264 KB |
Output is correct |
14 |
Correct |
1036 ms |
53580 KB |
Output is correct |
15 |
Correct |
1029 ms |
53264 KB |
Output is correct |
16 |
Correct |
1039 ms |
53720 KB |
Output is correct |
17 |
Correct |
1034 ms |
53816 KB |
Output is correct |
18 |
Correct |
1032 ms |
53772 KB |
Output is correct |
19 |
Correct |
1038 ms |
53544 KB |
Output is correct |
20 |
Correct |
1033 ms |
53608 KB |
Output is correct |
21 |
Correct |
1038 ms |
53768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1047 ms |
54096 KB |
Output is correct |
2 |
Correct |
1039 ms |
54100 KB |
Output is correct |
3 |
Correct |
1035 ms |
54220 KB |
Output is correct |
4 |
Correct |
1034 ms |
54444 KB |
Output is correct |
5 |
Correct |
1032 ms |
53972 KB |
Output is correct |
6 |
Correct |
1037 ms |
53480 KB |
Output is correct |
7 |
Correct |
1035 ms |
54020 KB |
Output is correct |
8 |
Correct |
1036 ms |
53760 KB |
Output is correct |
9 |
Correct |
1034 ms |
53632 KB |
Output is correct |
10 |
Correct |
1030 ms |
54040 KB |
Output is correct |
11 |
Correct |
1038 ms |
54104 KB |
Output is correct |
12 |
Correct |
1037 ms |
53880 KB |
Output is correct |
13 |
Correct |
1042 ms |
54264 KB |
Output is correct |
14 |
Correct |
1036 ms |
53580 KB |
Output is correct |
15 |
Correct |
1029 ms |
53264 KB |
Output is correct |
16 |
Correct |
1039 ms |
53720 KB |
Output is correct |
17 |
Correct |
1034 ms |
53816 KB |
Output is correct |
18 |
Correct |
1032 ms |
53772 KB |
Output is correct |
19 |
Correct |
1038 ms |
53544 KB |
Output is correct |
20 |
Correct |
1033 ms |
53608 KB |
Output is correct |
21 |
Correct |
1038 ms |
53768 KB |
Output is correct |
22 |
Correct |
1037 ms |
55316 KB |
Output is correct |
23 |
Correct |
1045 ms |
55540 KB |
Output is correct |
24 |
Correct |
1035 ms |
55560 KB |
Output is correct |
25 |
Correct |
1034 ms |
56104 KB |
Output is correct |
26 |
Correct |
1037 ms |
55272 KB |
Output is correct |
27 |
Correct |
1037 ms |
56048 KB |
Output is correct |
28 |
Correct |
1046 ms |
55872 KB |
Output is correct |
29 |
Correct |
1057 ms |
55412 KB |
Output is correct |
30 |
Correct |
1051 ms |
56220 KB |
Output is correct |
31 |
Correct |
1047 ms |
55776 KB |
Output is correct |
32 |
Correct |
1040 ms |
55660 KB |
Output is correct |
33 |
Correct |
1036 ms |
55892 KB |
Output is correct |
34 |
Correct |
1052 ms |
56024 KB |
Output is correct |
35 |
Correct |
1038 ms |
55332 KB |
Output is correct |
36 |
Correct |
1046 ms |
55424 KB |
Output is correct |
37 |
Correct |
1045 ms |
55956 KB |
Output is correct |
38 |
Correct |
1042 ms |
55740 KB |
Output is correct |
39 |
Correct |
1033 ms |
55624 KB |
Output is correct |
40 |
Correct |
1034 ms |
55892 KB |
Output is correct |
41 |
Correct |
1060 ms |
55996 KB |
Output is correct |
42 |
Correct |
1037 ms |
55180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1047 ms |
54096 KB |
Output is correct |
2 |
Correct |
1039 ms |
54100 KB |
Output is correct |
3 |
Correct |
1035 ms |
54220 KB |
Output is correct |
4 |
Correct |
1034 ms |
54444 KB |
Output is correct |
5 |
Correct |
1032 ms |
53972 KB |
Output is correct |
6 |
Correct |
1037 ms |
53480 KB |
Output is correct |
7 |
Correct |
1035 ms |
54020 KB |
Output is correct |
8 |
Correct |
1036 ms |
53760 KB |
Output is correct |
9 |
Correct |
1034 ms |
53632 KB |
Output is correct |
10 |
Correct |
1030 ms |
54040 KB |
Output is correct |
11 |
Correct |
1038 ms |
54104 KB |
Output is correct |
12 |
Correct |
1037 ms |
53880 KB |
Output is correct |
13 |
Correct |
1042 ms |
54264 KB |
Output is correct |
14 |
Correct |
1036 ms |
53580 KB |
Output is correct |
15 |
Correct |
1029 ms |
53264 KB |
Output is correct |
16 |
Correct |
1039 ms |
53720 KB |
Output is correct |
17 |
Correct |
1034 ms |
53816 KB |
Output is correct |
18 |
Correct |
1032 ms |
53772 KB |
Output is correct |
19 |
Correct |
1038 ms |
53544 KB |
Output is correct |
20 |
Correct |
1033 ms |
53608 KB |
Output is correct |
21 |
Correct |
1038 ms |
53768 KB |
Output is correct |
22 |
Correct |
1037 ms |
55316 KB |
Output is correct |
23 |
Correct |
1045 ms |
55540 KB |
Output is correct |
24 |
Correct |
1035 ms |
55560 KB |
Output is correct |
25 |
Correct |
1034 ms |
56104 KB |
Output is correct |
26 |
Correct |
1037 ms |
55272 KB |
Output is correct |
27 |
Correct |
1037 ms |
56048 KB |
Output is correct |
28 |
Correct |
1046 ms |
55872 KB |
Output is correct |
29 |
Correct |
1057 ms |
55412 KB |
Output is correct |
30 |
Correct |
1051 ms |
56220 KB |
Output is correct |
31 |
Correct |
1047 ms |
55776 KB |
Output is correct |
32 |
Correct |
1040 ms |
55660 KB |
Output is correct |
33 |
Correct |
1036 ms |
55892 KB |
Output is correct |
34 |
Correct |
1052 ms |
56024 KB |
Output is correct |
35 |
Correct |
1038 ms |
55332 KB |
Output is correct |
36 |
Correct |
1046 ms |
55424 KB |
Output is correct |
37 |
Correct |
1045 ms |
55956 KB |
Output is correct |
38 |
Correct |
1042 ms |
55740 KB |
Output is correct |
39 |
Correct |
1033 ms |
55624 KB |
Output is correct |
40 |
Correct |
1034 ms |
55892 KB |
Output is correct |
41 |
Correct |
1060 ms |
55996 KB |
Output is correct |
42 |
Correct |
1037 ms |
55180 KB |
Output is correct |
43 |
Correct |
1069 ms |
56124 KB |
Output is correct |
44 |
Correct |
1053 ms |
56896 KB |
Output is correct |
45 |
Correct |
1059 ms |
56708 KB |
Output is correct |
46 |
Correct |
1057 ms |
56704 KB |
Output is correct |
47 |
Correct |
1064 ms |
56536 KB |
Output is correct |
48 |
Correct |
1073 ms |
57592 KB |
Output is correct |
49 |
Correct |
1073 ms |
56488 KB |
Output is correct |
50 |
Correct |
1067 ms |
57484 KB |
Output is correct |
51 |
Correct |
1076 ms |
57236 KB |
Output is correct |
52 |
Correct |
1065 ms |
56368 KB |
Output is correct |
53 |
Correct |
1060 ms |
56540 KB |
Output is correct |
54 |
Correct |
1068 ms |
57132 KB |
Output is correct |
55 |
Correct |
1059 ms |
57032 KB |
Output is correct |
56 |
Correct |
1066 ms |
56664 KB |
Output is correct |
57 |
Correct |
1057 ms |
56716 KB |
Output is correct |
58 |
Correct |
1062 ms |
56756 KB |
Output is correct |
59 |
Correct |
1063 ms |
56644 KB |
Output is correct |
60 |
Correct |
1059 ms |
56484 KB |
Output is correct |
61 |
Correct |
1061 ms |
56736 KB |
Output is correct |
62 |
Correct |
1057 ms |
56588 KB |
Output is correct |
63 |
Correct |
1055 ms |
56620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1047 ms |
54096 KB |
Output is correct |
2 |
Correct |
1039 ms |
54100 KB |
Output is correct |
3 |
Correct |
1035 ms |
54220 KB |
Output is correct |
4 |
Correct |
1034 ms |
54444 KB |
Output is correct |
5 |
Correct |
1032 ms |
53972 KB |
Output is correct |
6 |
Correct |
1037 ms |
53480 KB |
Output is correct |
7 |
Correct |
1035 ms |
54020 KB |
Output is correct |
8 |
Correct |
1036 ms |
53760 KB |
Output is correct |
9 |
Correct |
1034 ms |
53632 KB |
Output is correct |
10 |
Correct |
1030 ms |
54040 KB |
Output is correct |
11 |
Correct |
1038 ms |
54104 KB |
Output is correct |
12 |
Correct |
1037 ms |
53880 KB |
Output is correct |
13 |
Correct |
1042 ms |
54264 KB |
Output is correct |
14 |
Correct |
1036 ms |
53580 KB |
Output is correct |
15 |
Correct |
1029 ms |
53264 KB |
Output is correct |
16 |
Correct |
1039 ms |
53720 KB |
Output is correct |
17 |
Correct |
1034 ms |
53816 KB |
Output is correct |
18 |
Correct |
1032 ms |
53772 KB |
Output is correct |
19 |
Correct |
1038 ms |
53544 KB |
Output is correct |
20 |
Correct |
1033 ms |
53608 KB |
Output is correct |
21 |
Correct |
1038 ms |
53768 KB |
Output is correct |
22 |
Correct |
1037 ms |
55316 KB |
Output is correct |
23 |
Correct |
1045 ms |
55540 KB |
Output is correct |
24 |
Correct |
1035 ms |
55560 KB |
Output is correct |
25 |
Correct |
1034 ms |
56104 KB |
Output is correct |
26 |
Correct |
1037 ms |
55272 KB |
Output is correct |
27 |
Correct |
1037 ms |
56048 KB |
Output is correct |
28 |
Correct |
1046 ms |
55872 KB |
Output is correct |
29 |
Correct |
1057 ms |
55412 KB |
Output is correct |
30 |
Correct |
1051 ms |
56220 KB |
Output is correct |
31 |
Correct |
1047 ms |
55776 KB |
Output is correct |
32 |
Correct |
1040 ms |
55660 KB |
Output is correct |
33 |
Correct |
1036 ms |
55892 KB |
Output is correct |
34 |
Correct |
1052 ms |
56024 KB |
Output is correct |
35 |
Correct |
1038 ms |
55332 KB |
Output is correct |
36 |
Correct |
1046 ms |
55424 KB |
Output is correct |
37 |
Correct |
1045 ms |
55956 KB |
Output is correct |
38 |
Correct |
1042 ms |
55740 KB |
Output is correct |
39 |
Correct |
1033 ms |
55624 KB |
Output is correct |
40 |
Correct |
1034 ms |
55892 KB |
Output is correct |
41 |
Correct |
1060 ms |
55996 KB |
Output is correct |
42 |
Correct |
1037 ms |
55180 KB |
Output is correct |
43 |
Correct |
1069 ms |
56124 KB |
Output is correct |
44 |
Correct |
1053 ms |
56896 KB |
Output is correct |
45 |
Correct |
1059 ms |
56708 KB |
Output is correct |
46 |
Correct |
1057 ms |
56704 KB |
Output is correct |
47 |
Correct |
1064 ms |
56536 KB |
Output is correct |
48 |
Correct |
1073 ms |
57592 KB |
Output is correct |
49 |
Correct |
1073 ms |
56488 KB |
Output is correct |
50 |
Correct |
1067 ms |
57484 KB |
Output is correct |
51 |
Correct |
1076 ms |
57236 KB |
Output is correct |
52 |
Correct |
1065 ms |
56368 KB |
Output is correct |
53 |
Correct |
1060 ms |
56540 KB |
Output is correct |
54 |
Correct |
1068 ms |
57132 KB |
Output is correct |
55 |
Correct |
1059 ms |
57032 KB |
Output is correct |
56 |
Correct |
1066 ms |
56664 KB |
Output is correct |
57 |
Correct |
1057 ms |
56716 KB |
Output is correct |
58 |
Correct |
1062 ms |
56756 KB |
Output is correct |
59 |
Correct |
1063 ms |
56644 KB |
Output is correct |
60 |
Correct |
1059 ms |
56484 KB |
Output is correct |
61 |
Correct |
1061 ms |
56736 KB |
Output is correct |
62 |
Correct |
1057 ms |
56588 KB |
Output is correct |
63 |
Correct |
1055 ms |
56620 KB |
Output is correct |
64 |
Correct |
1072 ms |
57376 KB |
Output is correct |
65 |
Correct |
1067 ms |
60096 KB |
Output is correct |
66 |
Correct |
1071 ms |
58576 KB |
Output is correct |
67 |
Correct |
1071 ms |
58796 KB |
Output is correct |
68 |
Correct |
1094 ms |
58044 KB |
Output is correct |
69 |
Correct |
1066 ms |
58856 KB |
Output is correct |
70 |
Correct |
1069 ms |
58672 KB |
Output is correct |
71 |
Correct |
1072 ms |
58372 KB |
Output is correct |
72 |
Correct |
1082 ms |
58568 KB |
Output is correct |
73 |
Correct |
1070 ms |
58880 KB |
Output is correct |
74 |
Correct |
1071 ms |
59684 KB |
Output is correct |
75 |
Correct |
1076 ms |
58624 KB |
Output is correct |
76 |
Correct |
1068 ms |
59228 KB |
Output is correct |
77 |
Correct |
1074 ms |
58104 KB |
Output is correct |
78 |
Correct |
1079 ms |
58448 KB |
Output is correct |
79 |
Correct |
1071 ms |
58284 KB |
Output is correct |
80 |
Correct |
1072 ms |
58416 KB |
Output is correct |
81 |
Correct |
1081 ms |
58936 KB |
Output is correct |
82 |
Correct |
1076 ms |
59632 KB |
Output is correct |
83 |
Correct |
1068 ms |
59252 KB |
Output is correct |
84 |
Correct |
1069 ms |
58904 KB |
Output is correct |