#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], mul[2][2][2];
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;
mul[0][0][0] = 24;
mul[1][0][0] = mul[0][1][0] = mul[0][0][1] = 12;
mul[1][1][0] = mul[0][1][1] = 4;
mul[1][0][1] = 6;
mul[1][1][1] = 1;
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 = i; j < C; j++)
for (int k = j; k < C; k++)
way[i][j][k] = 0;
for (int i = 0; i < C; i++)
for (int j = 0; j < C; j++)
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 = i; j < C; j++)
for (int k = j; 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 = i; j < C; j++)
for (int k = j; k < C; k++)
for (int l = k; l < C; l++)
ans = (ans + way[i][j][k] * way[i][j][l] % mod * way[i][k][l] % mod * way[j][k][l] % mod * mul[i == j][j == k][k == l]) % mod;
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
231 ms |
8004 KB |
Output is correct |
2 |
Correct |
239 ms |
8092 KB |
Output is correct |
3 |
Correct |
239 ms |
8144 KB |
Output is correct |
4 |
Correct |
208 ms |
8084 KB |
Output is correct |
5 |
Correct |
203 ms |
8228 KB |
Output is correct |
6 |
Correct |
214 ms |
8148 KB |
Output is correct |
7 |
Correct |
212 ms |
8128 KB |
Output is correct |
8 |
Correct |
191 ms |
8076 KB |
Output is correct |
9 |
Correct |
214 ms |
8128 KB |
Output is correct |
10 |
Correct |
209 ms |
8164 KB |
Output is correct |
11 |
Correct |
198 ms |
8232 KB |
Output is correct |
12 |
Correct |
199 ms |
8080 KB |
Output is correct |
13 |
Correct |
201 ms |
8168 KB |
Output is correct |
14 |
Correct |
203 ms |
8184 KB |
Output is correct |
15 |
Correct |
206 ms |
8040 KB |
Output is correct |
16 |
Correct |
189 ms |
8236 KB |
Output is correct |
17 |
Correct |
198 ms |
8172 KB |
Output is correct |
18 |
Correct |
195 ms |
8124 KB |
Output is correct |
19 |
Correct |
217 ms |
8136 KB |
Output is correct |
20 |
Correct |
204 ms |
8020 KB |
Output is correct |
21 |
Correct |
239 ms |
7940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
231 ms |
8004 KB |
Output is correct |
2 |
Correct |
239 ms |
8092 KB |
Output is correct |
3 |
Correct |
239 ms |
8144 KB |
Output is correct |
4 |
Correct |
208 ms |
8084 KB |
Output is correct |
5 |
Correct |
203 ms |
8228 KB |
Output is correct |
6 |
Correct |
214 ms |
8148 KB |
Output is correct |
7 |
Correct |
212 ms |
8128 KB |
Output is correct |
8 |
Correct |
191 ms |
8076 KB |
Output is correct |
9 |
Correct |
214 ms |
8128 KB |
Output is correct |
10 |
Correct |
209 ms |
8164 KB |
Output is correct |
11 |
Correct |
198 ms |
8232 KB |
Output is correct |
12 |
Correct |
199 ms |
8080 KB |
Output is correct |
13 |
Correct |
201 ms |
8168 KB |
Output is correct |
14 |
Correct |
203 ms |
8184 KB |
Output is correct |
15 |
Correct |
206 ms |
8040 KB |
Output is correct |
16 |
Correct |
189 ms |
8236 KB |
Output is correct |
17 |
Correct |
198 ms |
8172 KB |
Output is correct |
18 |
Correct |
195 ms |
8124 KB |
Output is correct |
19 |
Correct |
217 ms |
8136 KB |
Output is correct |
20 |
Correct |
204 ms |
8020 KB |
Output is correct |
21 |
Correct |
239 ms |
7940 KB |
Output is correct |
22 |
Correct |
217 ms |
7808 KB |
Output is correct |
23 |
Correct |
212 ms |
7820 KB |
Output is correct |
24 |
Correct |
207 ms |
8192 KB |
Output is correct |
25 |
Correct |
198 ms |
8064 KB |
Output is correct |
26 |
Correct |
223 ms |
8000 KB |
Output is correct |
27 |
Correct |
239 ms |
8072 KB |
Output is correct |
28 |
Correct |
202 ms |
7876 KB |
Output is correct |
29 |
Correct |
242 ms |
7912 KB |
Output is correct |
30 |
Correct |
223 ms |
7912 KB |
Output is correct |
31 |
Correct |
197 ms |
8204 KB |
Output is correct |
32 |
Correct |
217 ms |
7900 KB |
Output is correct |
33 |
Correct |
225 ms |
7912 KB |
Output is correct |
34 |
Correct |
195 ms |
7960 KB |
Output is correct |
35 |
Correct |
208 ms |
8116 KB |
Output is correct |
36 |
Correct |
212 ms |
7988 KB |
Output is correct |
37 |
Correct |
207 ms |
7908 KB |
Output is correct |
38 |
Correct |
210 ms |
8272 KB |
Output is correct |
39 |
Correct |
200 ms |
7912 KB |
Output is correct |
40 |
Correct |
192 ms |
7924 KB |
Output is correct |
41 |
Correct |
196 ms |
8028 KB |
Output is correct |
42 |
Correct |
197 ms |
7864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
231 ms |
8004 KB |
Output is correct |
2 |
Correct |
239 ms |
8092 KB |
Output is correct |
3 |
Correct |
239 ms |
8144 KB |
Output is correct |
4 |
Correct |
208 ms |
8084 KB |
Output is correct |
5 |
Correct |
203 ms |
8228 KB |
Output is correct |
6 |
Correct |
214 ms |
8148 KB |
Output is correct |
7 |
Correct |
212 ms |
8128 KB |
Output is correct |
8 |
Correct |
191 ms |
8076 KB |
Output is correct |
9 |
Correct |
214 ms |
8128 KB |
Output is correct |
10 |
Correct |
209 ms |
8164 KB |
Output is correct |
11 |
Correct |
198 ms |
8232 KB |
Output is correct |
12 |
Correct |
199 ms |
8080 KB |
Output is correct |
13 |
Correct |
201 ms |
8168 KB |
Output is correct |
14 |
Correct |
203 ms |
8184 KB |
Output is correct |
15 |
Correct |
206 ms |
8040 KB |
Output is correct |
16 |
Correct |
189 ms |
8236 KB |
Output is correct |
17 |
Correct |
198 ms |
8172 KB |
Output is correct |
18 |
Correct |
195 ms |
8124 KB |
Output is correct |
19 |
Correct |
217 ms |
8136 KB |
Output is correct |
20 |
Correct |
204 ms |
8020 KB |
Output is correct |
21 |
Correct |
239 ms |
7940 KB |
Output is correct |
22 |
Correct |
217 ms |
7808 KB |
Output is correct |
23 |
Correct |
212 ms |
7820 KB |
Output is correct |
24 |
Correct |
207 ms |
8192 KB |
Output is correct |
25 |
Correct |
198 ms |
8064 KB |
Output is correct |
26 |
Correct |
223 ms |
8000 KB |
Output is correct |
27 |
Correct |
239 ms |
8072 KB |
Output is correct |
28 |
Correct |
202 ms |
7876 KB |
Output is correct |
29 |
Correct |
242 ms |
7912 KB |
Output is correct |
30 |
Correct |
223 ms |
7912 KB |
Output is correct |
31 |
Correct |
197 ms |
8204 KB |
Output is correct |
32 |
Correct |
217 ms |
7900 KB |
Output is correct |
33 |
Correct |
225 ms |
7912 KB |
Output is correct |
34 |
Correct |
195 ms |
7960 KB |
Output is correct |
35 |
Correct |
208 ms |
8116 KB |
Output is correct |
36 |
Correct |
212 ms |
7988 KB |
Output is correct |
37 |
Correct |
207 ms |
7908 KB |
Output is correct |
38 |
Correct |
210 ms |
8272 KB |
Output is correct |
39 |
Correct |
200 ms |
7912 KB |
Output is correct |
40 |
Correct |
192 ms |
7924 KB |
Output is correct |
41 |
Correct |
196 ms |
8028 KB |
Output is correct |
42 |
Correct |
197 ms |
7864 KB |
Output is correct |
43 |
Correct |
200 ms |
7884 KB |
Output is correct |
44 |
Correct |
202 ms |
8008 KB |
Output is correct |
45 |
Correct |
194 ms |
8104 KB |
Output is correct |
46 |
Correct |
192 ms |
7908 KB |
Output is correct |
47 |
Correct |
190 ms |
7896 KB |
Output is correct |
48 |
Correct |
198 ms |
7916 KB |
Output is correct |
49 |
Correct |
199 ms |
8292 KB |
Output is correct |
50 |
Correct |
208 ms |
8312 KB |
Output is correct |
51 |
Correct |
206 ms |
8168 KB |
Output is correct |
52 |
Correct |
205 ms |
7840 KB |
Output is correct |
53 |
Correct |
214 ms |
7812 KB |
Output is correct |
54 |
Correct |
214 ms |
7912 KB |
Output is correct |
55 |
Correct |
222 ms |
7976 KB |
Output is correct |
56 |
Correct |
202 ms |
7912 KB |
Output is correct |
57 |
Correct |
206 ms |
7928 KB |
Output is correct |
58 |
Correct |
205 ms |
7996 KB |
Output is correct |
59 |
Correct |
196 ms |
8160 KB |
Output is correct |
60 |
Correct |
192 ms |
8172 KB |
Output is correct |
61 |
Correct |
218 ms |
7916 KB |
Output is correct |
62 |
Correct |
196 ms |
8044 KB |
Output is correct |
63 |
Correct |
220 ms |
7912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
231 ms |
8004 KB |
Output is correct |
2 |
Correct |
239 ms |
8092 KB |
Output is correct |
3 |
Correct |
239 ms |
8144 KB |
Output is correct |
4 |
Correct |
208 ms |
8084 KB |
Output is correct |
5 |
Correct |
203 ms |
8228 KB |
Output is correct |
6 |
Correct |
214 ms |
8148 KB |
Output is correct |
7 |
Correct |
212 ms |
8128 KB |
Output is correct |
8 |
Correct |
191 ms |
8076 KB |
Output is correct |
9 |
Correct |
214 ms |
8128 KB |
Output is correct |
10 |
Correct |
209 ms |
8164 KB |
Output is correct |
11 |
Correct |
198 ms |
8232 KB |
Output is correct |
12 |
Correct |
199 ms |
8080 KB |
Output is correct |
13 |
Correct |
201 ms |
8168 KB |
Output is correct |
14 |
Correct |
203 ms |
8184 KB |
Output is correct |
15 |
Correct |
206 ms |
8040 KB |
Output is correct |
16 |
Correct |
189 ms |
8236 KB |
Output is correct |
17 |
Correct |
198 ms |
8172 KB |
Output is correct |
18 |
Correct |
195 ms |
8124 KB |
Output is correct |
19 |
Correct |
217 ms |
8136 KB |
Output is correct |
20 |
Correct |
204 ms |
8020 KB |
Output is correct |
21 |
Correct |
239 ms |
7940 KB |
Output is correct |
22 |
Correct |
217 ms |
7808 KB |
Output is correct |
23 |
Correct |
212 ms |
7820 KB |
Output is correct |
24 |
Correct |
207 ms |
8192 KB |
Output is correct |
25 |
Correct |
198 ms |
8064 KB |
Output is correct |
26 |
Correct |
223 ms |
8000 KB |
Output is correct |
27 |
Correct |
239 ms |
8072 KB |
Output is correct |
28 |
Correct |
202 ms |
7876 KB |
Output is correct |
29 |
Correct |
242 ms |
7912 KB |
Output is correct |
30 |
Correct |
223 ms |
7912 KB |
Output is correct |
31 |
Correct |
197 ms |
8204 KB |
Output is correct |
32 |
Correct |
217 ms |
7900 KB |
Output is correct |
33 |
Correct |
225 ms |
7912 KB |
Output is correct |
34 |
Correct |
195 ms |
7960 KB |
Output is correct |
35 |
Correct |
208 ms |
8116 KB |
Output is correct |
36 |
Correct |
212 ms |
7988 KB |
Output is correct |
37 |
Correct |
207 ms |
7908 KB |
Output is correct |
38 |
Correct |
210 ms |
8272 KB |
Output is correct |
39 |
Correct |
200 ms |
7912 KB |
Output is correct |
40 |
Correct |
192 ms |
7924 KB |
Output is correct |
41 |
Correct |
196 ms |
8028 KB |
Output is correct |
42 |
Correct |
197 ms |
7864 KB |
Output is correct |
43 |
Correct |
200 ms |
7884 KB |
Output is correct |
44 |
Correct |
202 ms |
8008 KB |
Output is correct |
45 |
Correct |
194 ms |
8104 KB |
Output is correct |
46 |
Correct |
192 ms |
7908 KB |
Output is correct |
47 |
Correct |
190 ms |
7896 KB |
Output is correct |
48 |
Correct |
198 ms |
7916 KB |
Output is correct |
49 |
Correct |
199 ms |
8292 KB |
Output is correct |
50 |
Correct |
208 ms |
8312 KB |
Output is correct |
51 |
Correct |
206 ms |
8168 KB |
Output is correct |
52 |
Correct |
205 ms |
7840 KB |
Output is correct |
53 |
Correct |
214 ms |
7812 KB |
Output is correct |
54 |
Correct |
214 ms |
7912 KB |
Output is correct |
55 |
Correct |
222 ms |
7976 KB |
Output is correct |
56 |
Correct |
202 ms |
7912 KB |
Output is correct |
57 |
Correct |
206 ms |
7928 KB |
Output is correct |
58 |
Correct |
205 ms |
7996 KB |
Output is correct |
59 |
Correct |
196 ms |
8160 KB |
Output is correct |
60 |
Correct |
192 ms |
8172 KB |
Output is correct |
61 |
Correct |
218 ms |
7916 KB |
Output is correct |
62 |
Correct |
196 ms |
8044 KB |
Output is correct |
63 |
Correct |
220 ms |
7912 KB |
Output is correct |
64 |
Correct |
208 ms |
7916 KB |
Output is correct |
65 |
Correct |
204 ms |
7908 KB |
Output is correct |
66 |
Correct |
216 ms |
7892 KB |
Output is correct |
67 |
Correct |
199 ms |
8136 KB |
Output is correct |
68 |
Correct |
189 ms |
7800 KB |
Output is correct |
69 |
Correct |
239 ms |
8272 KB |
Output is correct |
70 |
Correct |
214 ms |
8008 KB |
Output is correct |
71 |
Correct |
192 ms |
7880 KB |
Output is correct |
72 |
Correct |
204 ms |
7912 KB |
Output is correct |
73 |
Correct |
200 ms |
8644 KB |
Output is correct |
74 |
Correct |
195 ms |
8968 KB |
Output is correct |
75 |
Correct |
205 ms |
8832 KB |
Output is correct |
76 |
Correct |
207 ms |
8668 KB |
Output is correct |
77 |
Correct |
201 ms |
8656 KB |
Output is correct |
78 |
Correct |
211 ms |
8612 KB |
Output is correct |
79 |
Correct |
197 ms |
8644 KB |
Output is correct |
80 |
Correct |
197 ms |
8912 KB |
Output is correct |
81 |
Correct |
196 ms |
8916 KB |
Output is correct |
82 |
Correct |
194 ms |
8908 KB |
Output is correct |
83 |
Correct |
212 ms |
8980 KB |
Output is correct |
84 |
Correct |
195 ms |
9040 KB |
Output is correct |