#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int M = 998244353, C = 62;
int cnt[C][C], f[C][C][C];
int conv(char c) {
if ('a' <= c && c <= 'z') {
return c - 'a';
}
if ('A' <= c && c <= 'Z') {
return c - 'A' + 26;
}
return c - '0' + 52;
}
void add(int &x, int y) {
if ((x += y) >= M) {
x -= M;
}
}
int solve(set<string> cnd) {
memset(cnt, 0, sizeof(cnt));
memset(f, 0, sizeof(f));
for (auto s : cnd) {
++cnt[conv(s[0])][conv(s.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) {
add(f[i][j][k], (long long) cnt[i][l] * cnt[j][l] % M * cnt[k][l] % M);
}
}
}
}
int res = 0;
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) {
int ways = (long long) f[i][j][k] * f[i][j][l] % M * f[i][k][l] % M * f[j][k][l] % M;
if (i == l) {
add(res, ways);
} else if (i == k || j == l) {
add(res, (long long) ways * 4 % M);
} else if (i == j && l == k) {
add(res, (long long) ways * 6 % M);
} else if (i == j || j == k || k == l) {
add(res, (long long) ways * 12 % M);
} else {
add(res, (long long) ways * 24 % M);
}
}
}
}
}
return res;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
array<set<string>, 10> buc;
while (n--) {
string s; cin >> s;
int l = s.size() - 1;
buc[l].insert(s);
reverse(s.begin(), s.end());
buc[l].insert(s);
}
int res = 0;
for (int i = 2; i < 10; ++i) {
add(res, solve(buc[i]));
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
224 ms |
19536 KB |
Output is correct |
2 |
Correct |
229 ms |
19536 KB |
Output is correct |
3 |
Correct |
215 ms |
19668 KB |
Output is correct |
4 |
Correct |
213 ms |
19540 KB |
Output is correct |
5 |
Correct |
214 ms |
19536 KB |
Output is correct |
6 |
Correct |
216 ms |
19536 KB |
Output is correct |
7 |
Correct |
220 ms |
19536 KB |
Output is correct |
8 |
Correct |
211 ms |
19540 KB |
Output is correct |
9 |
Correct |
223 ms |
19540 KB |
Output is correct |
10 |
Correct |
217 ms |
19536 KB |
Output is correct |
11 |
Correct |
216 ms |
19540 KB |
Output is correct |
12 |
Correct |
222 ms |
19624 KB |
Output is correct |
13 |
Correct |
223 ms |
19540 KB |
Output is correct |
14 |
Correct |
205 ms |
19708 KB |
Output is correct |
15 |
Correct |
215 ms |
19668 KB |
Output is correct |
16 |
Correct |
227 ms |
19472 KB |
Output is correct |
17 |
Correct |
218 ms |
19536 KB |
Output is correct |
18 |
Correct |
213 ms |
19544 KB |
Output is correct |
19 |
Correct |
221 ms |
19624 KB |
Output is correct |
20 |
Correct |
211 ms |
19540 KB |
Output is correct |
21 |
Correct |
213 ms |
19492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
224 ms |
19536 KB |
Output is correct |
2 |
Correct |
229 ms |
19536 KB |
Output is correct |
3 |
Correct |
215 ms |
19668 KB |
Output is correct |
4 |
Correct |
213 ms |
19540 KB |
Output is correct |
5 |
Correct |
214 ms |
19536 KB |
Output is correct |
6 |
Correct |
216 ms |
19536 KB |
Output is correct |
7 |
Correct |
220 ms |
19536 KB |
Output is correct |
8 |
Correct |
211 ms |
19540 KB |
Output is correct |
9 |
Correct |
223 ms |
19540 KB |
Output is correct |
10 |
Correct |
217 ms |
19536 KB |
Output is correct |
11 |
Correct |
216 ms |
19540 KB |
Output is correct |
12 |
Correct |
222 ms |
19624 KB |
Output is correct |
13 |
Correct |
223 ms |
19540 KB |
Output is correct |
14 |
Correct |
205 ms |
19708 KB |
Output is correct |
15 |
Correct |
215 ms |
19668 KB |
Output is correct |
16 |
Correct |
227 ms |
19472 KB |
Output is correct |
17 |
Correct |
218 ms |
19536 KB |
Output is correct |
18 |
Correct |
213 ms |
19544 KB |
Output is correct |
19 |
Correct |
221 ms |
19624 KB |
Output is correct |
20 |
Correct |
211 ms |
19540 KB |
Output is correct |
21 |
Correct |
213 ms |
19492 KB |
Output is correct |
22 |
Correct |
225 ms |
19280 KB |
Output is correct |
23 |
Correct |
214 ms |
19476 KB |
Output is correct |
24 |
Correct |
212 ms |
19488 KB |
Output is correct |
25 |
Correct |
217 ms |
19384 KB |
Output is correct |
26 |
Correct |
217 ms |
19424 KB |
Output is correct |
27 |
Correct |
230 ms |
19280 KB |
Output is correct |
28 |
Correct |
208 ms |
19280 KB |
Output is correct |
29 |
Correct |
216 ms |
19284 KB |
Output is correct |
30 |
Correct |
219 ms |
19280 KB |
Output is correct |
31 |
Correct |
214 ms |
19284 KB |
Output is correct |
32 |
Correct |
213 ms |
19396 KB |
Output is correct |
33 |
Correct |
225 ms |
19284 KB |
Output is correct |
34 |
Correct |
219 ms |
19484 KB |
Output is correct |
35 |
Correct |
220 ms |
19280 KB |
Output is correct |
36 |
Correct |
225 ms |
19284 KB |
Output is correct |
37 |
Correct |
225 ms |
19280 KB |
Output is correct |
38 |
Correct |
210 ms |
19280 KB |
Output is correct |
39 |
Correct |
222 ms |
19484 KB |
Output is correct |
40 |
Correct |
212 ms |
19332 KB |
Output is correct |
41 |
Correct |
219 ms |
19356 KB |
Output is correct |
42 |
Correct |
213 ms |
19284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
224 ms |
19536 KB |
Output is correct |
2 |
Correct |
229 ms |
19536 KB |
Output is correct |
3 |
Correct |
215 ms |
19668 KB |
Output is correct |
4 |
Correct |
213 ms |
19540 KB |
Output is correct |
5 |
Correct |
214 ms |
19536 KB |
Output is correct |
6 |
Correct |
216 ms |
19536 KB |
Output is correct |
7 |
Correct |
220 ms |
19536 KB |
Output is correct |
8 |
Correct |
211 ms |
19540 KB |
Output is correct |
9 |
Correct |
223 ms |
19540 KB |
Output is correct |
10 |
Correct |
217 ms |
19536 KB |
Output is correct |
11 |
Correct |
216 ms |
19540 KB |
Output is correct |
12 |
Correct |
222 ms |
19624 KB |
Output is correct |
13 |
Correct |
223 ms |
19540 KB |
Output is correct |
14 |
Correct |
205 ms |
19708 KB |
Output is correct |
15 |
Correct |
215 ms |
19668 KB |
Output is correct |
16 |
Correct |
227 ms |
19472 KB |
Output is correct |
17 |
Correct |
218 ms |
19536 KB |
Output is correct |
18 |
Correct |
213 ms |
19544 KB |
Output is correct |
19 |
Correct |
221 ms |
19624 KB |
Output is correct |
20 |
Correct |
211 ms |
19540 KB |
Output is correct |
21 |
Correct |
213 ms |
19492 KB |
Output is correct |
22 |
Correct |
225 ms |
19280 KB |
Output is correct |
23 |
Correct |
214 ms |
19476 KB |
Output is correct |
24 |
Correct |
212 ms |
19488 KB |
Output is correct |
25 |
Correct |
217 ms |
19384 KB |
Output is correct |
26 |
Correct |
217 ms |
19424 KB |
Output is correct |
27 |
Correct |
230 ms |
19280 KB |
Output is correct |
28 |
Correct |
208 ms |
19280 KB |
Output is correct |
29 |
Correct |
216 ms |
19284 KB |
Output is correct |
30 |
Correct |
219 ms |
19280 KB |
Output is correct |
31 |
Correct |
214 ms |
19284 KB |
Output is correct |
32 |
Correct |
213 ms |
19396 KB |
Output is correct |
33 |
Correct |
225 ms |
19284 KB |
Output is correct |
34 |
Correct |
219 ms |
19484 KB |
Output is correct |
35 |
Correct |
220 ms |
19280 KB |
Output is correct |
36 |
Correct |
225 ms |
19284 KB |
Output is correct |
37 |
Correct |
225 ms |
19280 KB |
Output is correct |
38 |
Correct |
210 ms |
19280 KB |
Output is correct |
39 |
Correct |
222 ms |
19484 KB |
Output is correct |
40 |
Correct |
212 ms |
19332 KB |
Output is correct |
41 |
Correct |
219 ms |
19356 KB |
Output is correct |
42 |
Correct |
213 ms |
19284 KB |
Output is correct |
43 |
Correct |
227 ms |
19284 KB |
Output is correct |
44 |
Correct |
213 ms |
19268 KB |
Output is correct |
45 |
Correct |
222 ms |
19284 KB |
Output is correct |
46 |
Correct |
214 ms |
19396 KB |
Output is correct |
47 |
Correct |
226 ms |
19284 KB |
Output is correct |
48 |
Correct |
221 ms |
19284 KB |
Output is correct |
49 |
Correct |
210 ms |
19280 KB |
Output is correct |
50 |
Correct |
224 ms |
19280 KB |
Output is correct |
51 |
Correct |
230 ms |
19304 KB |
Output is correct |
52 |
Correct |
216 ms |
19372 KB |
Output is correct |
53 |
Correct |
235 ms |
19284 KB |
Output is correct |
54 |
Correct |
220 ms |
19540 KB |
Output is correct |
55 |
Correct |
215 ms |
19280 KB |
Output is correct |
56 |
Correct |
218 ms |
19280 KB |
Output is correct |
57 |
Correct |
222 ms |
19292 KB |
Output is correct |
58 |
Correct |
220 ms |
19284 KB |
Output is correct |
59 |
Correct |
220 ms |
19280 KB |
Output is correct |
60 |
Correct |
219 ms |
19280 KB |
Output is correct |
61 |
Correct |
221 ms |
19540 KB |
Output is correct |
62 |
Correct |
220 ms |
19280 KB |
Output is correct |
63 |
Correct |
216 ms |
19304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
224 ms |
19536 KB |
Output is correct |
2 |
Correct |
229 ms |
19536 KB |
Output is correct |
3 |
Correct |
215 ms |
19668 KB |
Output is correct |
4 |
Correct |
213 ms |
19540 KB |
Output is correct |
5 |
Correct |
214 ms |
19536 KB |
Output is correct |
6 |
Correct |
216 ms |
19536 KB |
Output is correct |
7 |
Correct |
220 ms |
19536 KB |
Output is correct |
8 |
Correct |
211 ms |
19540 KB |
Output is correct |
9 |
Correct |
223 ms |
19540 KB |
Output is correct |
10 |
Correct |
217 ms |
19536 KB |
Output is correct |
11 |
Correct |
216 ms |
19540 KB |
Output is correct |
12 |
Correct |
222 ms |
19624 KB |
Output is correct |
13 |
Correct |
223 ms |
19540 KB |
Output is correct |
14 |
Correct |
205 ms |
19708 KB |
Output is correct |
15 |
Correct |
215 ms |
19668 KB |
Output is correct |
16 |
Correct |
227 ms |
19472 KB |
Output is correct |
17 |
Correct |
218 ms |
19536 KB |
Output is correct |
18 |
Correct |
213 ms |
19544 KB |
Output is correct |
19 |
Correct |
221 ms |
19624 KB |
Output is correct |
20 |
Correct |
211 ms |
19540 KB |
Output is correct |
21 |
Correct |
213 ms |
19492 KB |
Output is correct |
22 |
Correct |
225 ms |
19280 KB |
Output is correct |
23 |
Correct |
214 ms |
19476 KB |
Output is correct |
24 |
Correct |
212 ms |
19488 KB |
Output is correct |
25 |
Correct |
217 ms |
19384 KB |
Output is correct |
26 |
Correct |
217 ms |
19424 KB |
Output is correct |
27 |
Correct |
230 ms |
19280 KB |
Output is correct |
28 |
Correct |
208 ms |
19280 KB |
Output is correct |
29 |
Correct |
216 ms |
19284 KB |
Output is correct |
30 |
Correct |
219 ms |
19280 KB |
Output is correct |
31 |
Correct |
214 ms |
19284 KB |
Output is correct |
32 |
Correct |
213 ms |
19396 KB |
Output is correct |
33 |
Correct |
225 ms |
19284 KB |
Output is correct |
34 |
Correct |
219 ms |
19484 KB |
Output is correct |
35 |
Correct |
220 ms |
19280 KB |
Output is correct |
36 |
Correct |
225 ms |
19284 KB |
Output is correct |
37 |
Correct |
225 ms |
19280 KB |
Output is correct |
38 |
Correct |
210 ms |
19280 KB |
Output is correct |
39 |
Correct |
222 ms |
19484 KB |
Output is correct |
40 |
Correct |
212 ms |
19332 KB |
Output is correct |
41 |
Correct |
219 ms |
19356 KB |
Output is correct |
42 |
Correct |
213 ms |
19284 KB |
Output is correct |
43 |
Correct |
227 ms |
19284 KB |
Output is correct |
44 |
Correct |
213 ms |
19268 KB |
Output is correct |
45 |
Correct |
222 ms |
19284 KB |
Output is correct |
46 |
Correct |
214 ms |
19396 KB |
Output is correct |
47 |
Correct |
226 ms |
19284 KB |
Output is correct |
48 |
Correct |
221 ms |
19284 KB |
Output is correct |
49 |
Correct |
210 ms |
19280 KB |
Output is correct |
50 |
Correct |
224 ms |
19280 KB |
Output is correct |
51 |
Correct |
230 ms |
19304 KB |
Output is correct |
52 |
Correct |
216 ms |
19372 KB |
Output is correct |
53 |
Correct |
235 ms |
19284 KB |
Output is correct |
54 |
Correct |
220 ms |
19540 KB |
Output is correct |
55 |
Correct |
215 ms |
19280 KB |
Output is correct |
56 |
Correct |
218 ms |
19280 KB |
Output is correct |
57 |
Correct |
222 ms |
19292 KB |
Output is correct |
58 |
Correct |
220 ms |
19284 KB |
Output is correct |
59 |
Correct |
220 ms |
19280 KB |
Output is correct |
60 |
Correct |
219 ms |
19280 KB |
Output is correct |
61 |
Correct |
221 ms |
19540 KB |
Output is correct |
62 |
Correct |
220 ms |
19280 KB |
Output is correct |
63 |
Correct |
216 ms |
19304 KB |
Output is correct |
64 |
Correct |
230 ms |
19472 KB |
Output is correct |
65 |
Correct |
220 ms |
19548 KB |
Output is correct |
66 |
Correct |
221 ms |
19524 KB |
Output is correct |
67 |
Correct |
221 ms |
19536 KB |
Output is correct |
68 |
Correct |
218 ms |
19612 KB |
Output is correct |
69 |
Correct |
214 ms |
19464 KB |
Output is correct |
70 |
Correct |
228 ms |
19540 KB |
Output is correct |
71 |
Correct |
217 ms |
19536 KB |
Output is correct |
72 |
Correct |
222 ms |
19792 KB |
Output is correct |
73 |
Correct |
213 ms |
19540 KB |
Output is correct |
74 |
Correct |
216 ms |
19656 KB |
Output is correct |
75 |
Correct |
234 ms |
19456 KB |
Output is correct |
76 |
Correct |
220 ms |
19504 KB |
Output is correct |
77 |
Correct |
222 ms |
19568 KB |
Output is correct |
78 |
Correct |
222 ms |
19792 KB |
Output is correct |
79 |
Correct |
221 ms |
19536 KB |
Output is correct |
80 |
Correct |
214 ms |
19576 KB |
Output is correct |
81 |
Correct |
236 ms |
19536 KB |
Output is correct |
82 |
Correct |
216 ms |
19536 KB |
Output is correct |
83 |
Correct |
212 ms |
19536 KB |
Output is correct |
84 |
Correct |
223 ms |
19796 KB |
Output is correct |