#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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
20304 KB |
Output is correct |
2 |
Correct |
329 ms |
20320 KB |
Output is correct |
3 |
Correct |
335 ms |
20328 KB |
Output is correct |
4 |
Correct |
323 ms |
20316 KB |
Output is correct |
5 |
Correct |
327 ms |
20260 KB |
Output is correct |
6 |
Correct |
325 ms |
20332 KB |
Output is correct |
7 |
Correct |
307 ms |
20340 KB |
Output is correct |
8 |
Correct |
325 ms |
20324 KB |
Output is correct |
9 |
Correct |
327 ms |
20268 KB |
Output is correct |
10 |
Correct |
333 ms |
20340 KB |
Output is correct |
11 |
Correct |
328 ms |
20236 KB |
Output is correct |
12 |
Correct |
334 ms |
20228 KB |
Output is correct |
13 |
Correct |
344 ms |
20340 KB |
Output is correct |
14 |
Correct |
336 ms |
20328 KB |
Output is correct |
15 |
Correct |
323 ms |
20340 KB |
Output is correct |
16 |
Correct |
322 ms |
20188 KB |
Output is correct |
17 |
Correct |
333 ms |
20228 KB |
Output is correct |
18 |
Correct |
331 ms |
20216 KB |
Output is correct |
19 |
Correct |
331 ms |
20316 KB |
Output is correct |
20 |
Correct |
334 ms |
20276 KB |
Output is correct |
21 |
Correct |
335 ms |
20296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
20304 KB |
Output is correct |
2 |
Correct |
329 ms |
20320 KB |
Output is correct |
3 |
Correct |
335 ms |
20328 KB |
Output is correct |
4 |
Correct |
323 ms |
20316 KB |
Output is correct |
5 |
Correct |
327 ms |
20260 KB |
Output is correct |
6 |
Correct |
325 ms |
20332 KB |
Output is correct |
7 |
Correct |
307 ms |
20340 KB |
Output is correct |
8 |
Correct |
325 ms |
20324 KB |
Output is correct |
9 |
Correct |
327 ms |
20268 KB |
Output is correct |
10 |
Correct |
333 ms |
20340 KB |
Output is correct |
11 |
Correct |
328 ms |
20236 KB |
Output is correct |
12 |
Correct |
334 ms |
20228 KB |
Output is correct |
13 |
Correct |
344 ms |
20340 KB |
Output is correct |
14 |
Correct |
336 ms |
20328 KB |
Output is correct |
15 |
Correct |
323 ms |
20340 KB |
Output is correct |
16 |
Correct |
322 ms |
20188 KB |
Output is correct |
17 |
Correct |
333 ms |
20228 KB |
Output is correct |
18 |
Correct |
331 ms |
20216 KB |
Output is correct |
19 |
Correct |
331 ms |
20316 KB |
Output is correct |
20 |
Correct |
334 ms |
20276 KB |
Output is correct |
21 |
Correct |
335 ms |
20296 KB |
Output is correct |
22 |
Correct |
339 ms |
20980 KB |
Output is correct |
23 |
Correct |
340 ms |
20996 KB |
Output is correct |
24 |
Correct |
325 ms |
21012 KB |
Output is correct |
25 |
Correct |
331 ms |
20908 KB |
Output is correct |
26 |
Correct |
342 ms |
20912 KB |
Output is correct |
27 |
Correct |
334 ms |
20912 KB |
Output is correct |
28 |
Correct |
333 ms |
20892 KB |
Output is correct |
29 |
Correct |
338 ms |
20916 KB |
Output is correct |
30 |
Correct |
331 ms |
20916 KB |
Output is correct |
31 |
Correct |
340 ms |
20992 KB |
Output is correct |
32 |
Correct |
333 ms |
20976 KB |
Output is correct |
33 |
Correct |
337 ms |
20900 KB |
Output is correct |
34 |
Correct |
333 ms |
20900 KB |
Output is correct |
35 |
Correct |
331 ms |
20904 KB |
Output is correct |
36 |
Correct |
342 ms |
20952 KB |
Output is correct |
37 |
Correct |
340 ms |
20992 KB |
Output is correct |
38 |
Correct |
338 ms |
20968 KB |
Output is correct |
39 |
Correct |
336 ms |
20928 KB |
Output is correct |
40 |
Correct |
344 ms |
20988 KB |
Output is correct |
41 |
Correct |
331 ms |
20984 KB |
Output is correct |
42 |
Correct |
337 ms |
21008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
20304 KB |
Output is correct |
2 |
Correct |
329 ms |
20320 KB |
Output is correct |
3 |
Correct |
335 ms |
20328 KB |
Output is correct |
4 |
Correct |
323 ms |
20316 KB |
Output is correct |
5 |
Correct |
327 ms |
20260 KB |
Output is correct |
6 |
Correct |
325 ms |
20332 KB |
Output is correct |
7 |
Correct |
307 ms |
20340 KB |
Output is correct |
8 |
Correct |
325 ms |
20324 KB |
Output is correct |
9 |
Correct |
327 ms |
20268 KB |
Output is correct |
10 |
Correct |
333 ms |
20340 KB |
Output is correct |
11 |
Correct |
328 ms |
20236 KB |
Output is correct |
12 |
Correct |
334 ms |
20228 KB |
Output is correct |
13 |
Correct |
344 ms |
20340 KB |
Output is correct |
14 |
Correct |
336 ms |
20328 KB |
Output is correct |
15 |
Correct |
323 ms |
20340 KB |
Output is correct |
16 |
Correct |
322 ms |
20188 KB |
Output is correct |
17 |
Correct |
333 ms |
20228 KB |
Output is correct |
18 |
Correct |
331 ms |
20216 KB |
Output is correct |
19 |
Correct |
331 ms |
20316 KB |
Output is correct |
20 |
Correct |
334 ms |
20276 KB |
Output is correct |
21 |
Correct |
335 ms |
20296 KB |
Output is correct |
22 |
Correct |
339 ms |
20980 KB |
Output is correct |
23 |
Correct |
340 ms |
20996 KB |
Output is correct |
24 |
Correct |
325 ms |
21012 KB |
Output is correct |
25 |
Correct |
331 ms |
20908 KB |
Output is correct |
26 |
Correct |
342 ms |
20912 KB |
Output is correct |
27 |
Correct |
334 ms |
20912 KB |
Output is correct |
28 |
Correct |
333 ms |
20892 KB |
Output is correct |
29 |
Correct |
338 ms |
20916 KB |
Output is correct |
30 |
Correct |
331 ms |
20916 KB |
Output is correct |
31 |
Correct |
340 ms |
20992 KB |
Output is correct |
32 |
Correct |
333 ms |
20976 KB |
Output is correct |
33 |
Correct |
337 ms |
20900 KB |
Output is correct |
34 |
Correct |
333 ms |
20900 KB |
Output is correct |
35 |
Correct |
331 ms |
20904 KB |
Output is correct |
36 |
Correct |
342 ms |
20952 KB |
Output is correct |
37 |
Correct |
340 ms |
20992 KB |
Output is correct |
38 |
Correct |
338 ms |
20968 KB |
Output is correct |
39 |
Correct |
336 ms |
20928 KB |
Output is correct |
40 |
Correct |
344 ms |
20988 KB |
Output is correct |
41 |
Correct |
331 ms |
20984 KB |
Output is correct |
42 |
Correct |
337 ms |
21008 KB |
Output is correct |
43 |
Correct |
338 ms |
21172 KB |
Output is correct |
44 |
Correct |
337 ms |
21328 KB |
Output is correct |
45 |
Correct |
331 ms |
21380 KB |
Output is correct |
46 |
Correct |
331 ms |
21288 KB |
Output is correct |
47 |
Correct |
329 ms |
21240 KB |
Output is correct |
48 |
Correct |
334 ms |
21264 KB |
Output is correct |
49 |
Correct |
328 ms |
21212 KB |
Output is correct |
50 |
Correct |
335 ms |
21268 KB |
Output is correct |
51 |
Correct |
343 ms |
21208 KB |
Output is correct |
52 |
Correct |
328 ms |
21340 KB |
Output is correct |
53 |
Correct |
325 ms |
21264 KB |
Output is correct |
54 |
Correct |
360 ms |
21144 KB |
Output is correct |
55 |
Correct |
382 ms |
21224 KB |
Output is correct |
56 |
Correct |
386 ms |
21264 KB |
Output is correct |
57 |
Correct |
362 ms |
21032 KB |
Output is correct |
58 |
Correct |
336 ms |
21376 KB |
Output is correct |
59 |
Correct |
325 ms |
21236 KB |
Output is correct |
60 |
Correct |
332 ms |
21260 KB |
Output is correct |
61 |
Correct |
334 ms |
21216 KB |
Output is correct |
62 |
Correct |
338 ms |
21240 KB |
Output is correct |
63 |
Correct |
327 ms |
21156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
20304 KB |
Output is correct |
2 |
Correct |
329 ms |
20320 KB |
Output is correct |
3 |
Correct |
335 ms |
20328 KB |
Output is correct |
4 |
Correct |
323 ms |
20316 KB |
Output is correct |
5 |
Correct |
327 ms |
20260 KB |
Output is correct |
6 |
Correct |
325 ms |
20332 KB |
Output is correct |
7 |
Correct |
307 ms |
20340 KB |
Output is correct |
8 |
Correct |
325 ms |
20324 KB |
Output is correct |
9 |
Correct |
327 ms |
20268 KB |
Output is correct |
10 |
Correct |
333 ms |
20340 KB |
Output is correct |
11 |
Correct |
328 ms |
20236 KB |
Output is correct |
12 |
Correct |
334 ms |
20228 KB |
Output is correct |
13 |
Correct |
344 ms |
20340 KB |
Output is correct |
14 |
Correct |
336 ms |
20328 KB |
Output is correct |
15 |
Correct |
323 ms |
20340 KB |
Output is correct |
16 |
Correct |
322 ms |
20188 KB |
Output is correct |
17 |
Correct |
333 ms |
20228 KB |
Output is correct |
18 |
Correct |
331 ms |
20216 KB |
Output is correct |
19 |
Correct |
331 ms |
20316 KB |
Output is correct |
20 |
Correct |
334 ms |
20276 KB |
Output is correct |
21 |
Correct |
335 ms |
20296 KB |
Output is correct |
22 |
Correct |
339 ms |
20980 KB |
Output is correct |
23 |
Correct |
340 ms |
20996 KB |
Output is correct |
24 |
Correct |
325 ms |
21012 KB |
Output is correct |
25 |
Correct |
331 ms |
20908 KB |
Output is correct |
26 |
Correct |
342 ms |
20912 KB |
Output is correct |
27 |
Correct |
334 ms |
20912 KB |
Output is correct |
28 |
Correct |
333 ms |
20892 KB |
Output is correct |
29 |
Correct |
338 ms |
20916 KB |
Output is correct |
30 |
Correct |
331 ms |
20916 KB |
Output is correct |
31 |
Correct |
340 ms |
20992 KB |
Output is correct |
32 |
Correct |
333 ms |
20976 KB |
Output is correct |
33 |
Correct |
337 ms |
20900 KB |
Output is correct |
34 |
Correct |
333 ms |
20900 KB |
Output is correct |
35 |
Correct |
331 ms |
20904 KB |
Output is correct |
36 |
Correct |
342 ms |
20952 KB |
Output is correct |
37 |
Correct |
340 ms |
20992 KB |
Output is correct |
38 |
Correct |
338 ms |
20968 KB |
Output is correct |
39 |
Correct |
336 ms |
20928 KB |
Output is correct |
40 |
Correct |
344 ms |
20988 KB |
Output is correct |
41 |
Correct |
331 ms |
20984 KB |
Output is correct |
42 |
Correct |
337 ms |
21008 KB |
Output is correct |
43 |
Correct |
338 ms |
21172 KB |
Output is correct |
44 |
Correct |
337 ms |
21328 KB |
Output is correct |
45 |
Correct |
331 ms |
21380 KB |
Output is correct |
46 |
Correct |
331 ms |
21288 KB |
Output is correct |
47 |
Correct |
329 ms |
21240 KB |
Output is correct |
48 |
Correct |
334 ms |
21264 KB |
Output is correct |
49 |
Correct |
328 ms |
21212 KB |
Output is correct |
50 |
Correct |
335 ms |
21268 KB |
Output is correct |
51 |
Correct |
343 ms |
21208 KB |
Output is correct |
52 |
Correct |
328 ms |
21340 KB |
Output is correct |
53 |
Correct |
325 ms |
21264 KB |
Output is correct |
54 |
Correct |
360 ms |
21144 KB |
Output is correct |
55 |
Correct |
382 ms |
21224 KB |
Output is correct |
56 |
Correct |
386 ms |
21264 KB |
Output is correct |
57 |
Correct |
362 ms |
21032 KB |
Output is correct |
58 |
Correct |
336 ms |
21376 KB |
Output is correct |
59 |
Correct |
325 ms |
21236 KB |
Output is correct |
60 |
Correct |
332 ms |
21260 KB |
Output is correct |
61 |
Correct |
334 ms |
21216 KB |
Output is correct |
62 |
Correct |
338 ms |
21240 KB |
Output is correct |
63 |
Correct |
327 ms |
21156 KB |
Output is correct |
64 |
Correct |
332 ms |
21384 KB |
Output is correct |
65 |
Correct |
335 ms |
21512 KB |
Output is correct |
66 |
Correct |
337 ms |
21448 KB |
Output is correct |
67 |
Correct |
352 ms |
21508 KB |
Output is correct |
68 |
Correct |
337 ms |
21496 KB |
Output is correct |
69 |
Correct |
340 ms |
21396 KB |
Output is correct |
70 |
Correct |
331 ms |
21496 KB |
Output is correct |
71 |
Correct |
339 ms |
21556 KB |
Output is correct |
72 |
Correct |
339 ms |
21544 KB |
Output is correct |
73 |
Correct |
336 ms |
21416 KB |
Output is correct |
74 |
Correct |
369 ms |
21492 KB |
Output is correct |
75 |
Correct |
325 ms |
21488 KB |
Output is correct |
76 |
Correct |
337 ms |
21628 KB |
Output is correct |
77 |
Correct |
337 ms |
21536 KB |
Output is correct |
78 |
Correct |
339 ms |
21420 KB |
Output is correct |
79 |
Correct |
335 ms |
21464 KB |
Output is correct |
80 |
Correct |
330 ms |
21496 KB |
Output is correct |
81 |
Correct |
348 ms |
21436 KB |
Output is correct |
82 |
Correct |
338 ms |
21496 KB |
Output is correct |
83 |
Correct |
334 ms |
21508 KB |
Output is correct |
84 |
Correct |
360 ms |
21524 KB |
Output is correct |