#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<unordered_set>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
const int N = 1e5 + 9, mod = 998244353;
int n;
int a[11][62][62][2];
bool palind(string s) {
int l(0), r(s.size() - 1);
while (l < r) {
if (s[l] != s[r]) return false;
++l, --r;
}
return true;
}
int num(char c) {
if ('a' <= c && c <= 'z') return c - 'a';
if ('A' <= c && c <= 'Z') return c - 'A' + 26;
if ('0' <= c && c <= '9') return c - '0' + 52;
return -1;
}
ll calc(int len, int i, int j) {
if (i != j) {
if (i > j) swap(i, j);
return a[len][i][j][0];
}
return (a[len][i][j][1] + a[len][i][j][0] * 2) % mod;
}
ll perm[62][62][62][62], d[62][62][62];
void build_d(int len) {
for (int i1 = 0; i1 < n; ++i1)
for (int i2 = i1; i2 < n; ++i2)
for (int i3 = i2; i3 < n; ++i3) {
d[i1][i2][i3] = 0;
for (int i = 0; i < n; ++i)
(d[i1][i2][i3] += calc(len, i, i1) * calc(len, i, i2) % mod * calc(len, i, i3)) %= mod;
}
}
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> n;
unordered_set<string> S;
vector<int> ch;
for (int ii = 0; ii < n; ++ii) {
string s; cin >> s;
if (S.count(s)) continue;
int i = num(s[0]), j = num(s.back());
if (i > j) swap(i, j);
ch.push_back(i);
ch.push_back(j);
++a[s.size()][i][j][palind(s)];
reverse(all(s));
S.insert(s);
}
sort(all(ch));
ch.resize(unique(all(ch)) - ch.begin());
n = ch.size();
for (int len = 3; len <= 10; ++len)
for (int i = 0; i < n; ++i)
for (int j = i; j < n; ++j) {
int i1 = ch[i], i2 = ch[j];
a[len][i][j][0] = a[len][i1][i2][0];
a[len][i][j][1] = a[len][i1][i2][1];
}
for (int i1 = 0; i1 < n; ++i1)
for (int i2 = i1; i2 < n; ++i2)
for (int i3 = i2; i3 < n; ++i3)
for (int i4 = i3; i4 < n; ++i4) {
perm[i1][i2][i3][i4] = i1 == i4 ? 1 : i1 == i3 || i2 == i4 ? 4 : i1 == i2 && i3 == i4 ? 6 : i1 == i2 || i2 == i3 || i3 == i4 ? 12 : 24;
}
ll ans(0);
for (int len = 3; len <= 10; ++len) {
build_d(len);
for (int i1 = 0; i1 < n; ++i1)
for (int i2 = i1; i2 < n; ++i2)
for (int i3 = i2; i3 < n; ++i3)
for (int i4 = i3; i4 < n; ++i4)
(ans += d[i1][i2][i3] * d[i1][i2][i4] % mod * d[i1][i3][i4] % mod * d[i2][i3][i4] % mod * perm[i1][i2][i3][i4]) %= mod;
}
cout << ans << '\n';
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
8404 KB |
Output is correct |
2 |
Correct |
42 ms |
8388 KB |
Output is correct |
3 |
Correct |
44 ms |
8388 KB |
Output is correct |
4 |
Correct |
52 ms |
8380 KB |
Output is correct |
5 |
Correct |
51 ms |
8396 KB |
Output is correct |
6 |
Correct |
49 ms |
8356 KB |
Output is correct |
7 |
Correct |
44 ms |
8444 KB |
Output is correct |
8 |
Correct |
44 ms |
8360 KB |
Output is correct |
9 |
Correct |
44 ms |
8392 KB |
Output is correct |
10 |
Correct |
44 ms |
8404 KB |
Output is correct |
11 |
Correct |
59 ms |
8332 KB |
Output is correct |
12 |
Correct |
49 ms |
8380 KB |
Output is correct |
13 |
Correct |
43 ms |
8396 KB |
Output is correct |
14 |
Correct |
43 ms |
8332 KB |
Output is correct |
15 |
Correct |
44 ms |
8396 KB |
Output is correct |
16 |
Correct |
57 ms |
8408 KB |
Output is correct |
17 |
Correct |
51 ms |
8404 KB |
Output is correct |
18 |
Correct |
44 ms |
8404 KB |
Output is correct |
19 |
Correct |
52 ms |
8612 KB |
Output is correct |
20 |
Correct |
47 ms |
8396 KB |
Output is correct |
21 |
Correct |
43 ms |
8368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
8404 KB |
Output is correct |
2 |
Correct |
42 ms |
8388 KB |
Output is correct |
3 |
Correct |
44 ms |
8388 KB |
Output is correct |
4 |
Correct |
52 ms |
8380 KB |
Output is correct |
5 |
Correct |
51 ms |
8396 KB |
Output is correct |
6 |
Correct |
49 ms |
8356 KB |
Output is correct |
7 |
Correct |
44 ms |
8444 KB |
Output is correct |
8 |
Correct |
44 ms |
8360 KB |
Output is correct |
9 |
Correct |
44 ms |
8392 KB |
Output is correct |
10 |
Correct |
44 ms |
8404 KB |
Output is correct |
11 |
Correct |
59 ms |
8332 KB |
Output is correct |
12 |
Correct |
49 ms |
8380 KB |
Output is correct |
13 |
Correct |
43 ms |
8396 KB |
Output is correct |
14 |
Correct |
43 ms |
8332 KB |
Output is correct |
15 |
Correct |
44 ms |
8396 KB |
Output is correct |
16 |
Correct |
57 ms |
8408 KB |
Output is correct |
17 |
Correct |
51 ms |
8404 KB |
Output is correct |
18 |
Correct |
44 ms |
8404 KB |
Output is correct |
19 |
Correct |
52 ms |
8612 KB |
Output is correct |
20 |
Correct |
47 ms |
8396 KB |
Output is correct |
21 |
Correct |
43 ms |
8368 KB |
Output is correct |
22 |
Correct |
69 ms |
9648 KB |
Output is correct |
23 |
Correct |
53 ms |
9624 KB |
Output is correct |
24 |
Correct |
46 ms |
9608 KB |
Output is correct |
25 |
Correct |
46 ms |
9648 KB |
Output is correct |
26 |
Correct |
48 ms |
9576 KB |
Output is correct |
27 |
Correct |
49 ms |
9596 KB |
Output is correct |
28 |
Correct |
53 ms |
9648 KB |
Output is correct |
29 |
Correct |
47 ms |
9676 KB |
Output is correct |
30 |
Correct |
49 ms |
9580 KB |
Output is correct |
31 |
Correct |
47 ms |
9580 KB |
Output is correct |
32 |
Correct |
45 ms |
9660 KB |
Output is correct |
33 |
Correct |
52 ms |
9648 KB |
Output is correct |
34 |
Correct |
60 ms |
9568 KB |
Output is correct |
35 |
Correct |
45 ms |
9596 KB |
Output is correct |
36 |
Correct |
58 ms |
9680 KB |
Output is correct |
37 |
Correct |
47 ms |
9624 KB |
Output is correct |
38 |
Correct |
53 ms |
9624 KB |
Output is correct |
39 |
Correct |
67 ms |
9692 KB |
Output is correct |
40 |
Correct |
58 ms |
9564 KB |
Output is correct |
41 |
Correct |
50 ms |
9604 KB |
Output is correct |
42 |
Correct |
46 ms |
9676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
8404 KB |
Output is correct |
2 |
Correct |
42 ms |
8388 KB |
Output is correct |
3 |
Correct |
44 ms |
8388 KB |
Output is correct |
4 |
Correct |
52 ms |
8380 KB |
Output is correct |
5 |
Correct |
51 ms |
8396 KB |
Output is correct |
6 |
Correct |
49 ms |
8356 KB |
Output is correct |
7 |
Correct |
44 ms |
8444 KB |
Output is correct |
8 |
Correct |
44 ms |
8360 KB |
Output is correct |
9 |
Correct |
44 ms |
8392 KB |
Output is correct |
10 |
Correct |
44 ms |
8404 KB |
Output is correct |
11 |
Correct |
59 ms |
8332 KB |
Output is correct |
12 |
Correct |
49 ms |
8380 KB |
Output is correct |
13 |
Correct |
43 ms |
8396 KB |
Output is correct |
14 |
Correct |
43 ms |
8332 KB |
Output is correct |
15 |
Correct |
44 ms |
8396 KB |
Output is correct |
16 |
Correct |
57 ms |
8408 KB |
Output is correct |
17 |
Correct |
51 ms |
8404 KB |
Output is correct |
18 |
Correct |
44 ms |
8404 KB |
Output is correct |
19 |
Correct |
52 ms |
8612 KB |
Output is correct |
20 |
Correct |
47 ms |
8396 KB |
Output is correct |
21 |
Correct |
43 ms |
8368 KB |
Output is correct |
22 |
Correct |
69 ms |
9648 KB |
Output is correct |
23 |
Correct |
53 ms |
9624 KB |
Output is correct |
24 |
Correct |
46 ms |
9608 KB |
Output is correct |
25 |
Correct |
46 ms |
9648 KB |
Output is correct |
26 |
Correct |
48 ms |
9576 KB |
Output is correct |
27 |
Correct |
49 ms |
9596 KB |
Output is correct |
28 |
Correct |
53 ms |
9648 KB |
Output is correct |
29 |
Correct |
47 ms |
9676 KB |
Output is correct |
30 |
Correct |
49 ms |
9580 KB |
Output is correct |
31 |
Correct |
47 ms |
9580 KB |
Output is correct |
32 |
Correct |
45 ms |
9660 KB |
Output is correct |
33 |
Correct |
52 ms |
9648 KB |
Output is correct |
34 |
Correct |
60 ms |
9568 KB |
Output is correct |
35 |
Correct |
45 ms |
9596 KB |
Output is correct |
36 |
Correct |
58 ms |
9680 KB |
Output is correct |
37 |
Correct |
47 ms |
9624 KB |
Output is correct |
38 |
Correct |
53 ms |
9624 KB |
Output is correct |
39 |
Correct |
67 ms |
9692 KB |
Output is correct |
40 |
Correct |
58 ms |
9564 KB |
Output is correct |
41 |
Correct |
50 ms |
9604 KB |
Output is correct |
42 |
Correct |
46 ms |
9676 KB |
Output is correct |
43 |
Correct |
67 ms |
14152 KB |
Output is correct |
44 |
Correct |
70 ms |
14188 KB |
Output is correct |
45 |
Correct |
66 ms |
14144 KB |
Output is correct |
46 |
Correct |
62 ms |
14124 KB |
Output is correct |
47 |
Correct |
64 ms |
14196 KB |
Output is correct |
48 |
Correct |
69 ms |
14128 KB |
Output is correct |
49 |
Correct |
62 ms |
14076 KB |
Output is correct |
50 |
Correct |
67 ms |
14192 KB |
Output is correct |
51 |
Correct |
67 ms |
14184 KB |
Output is correct |
52 |
Correct |
72 ms |
14096 KB |
Output is correct |
53 |
Correct |
75 ms |
14188 KB |
Output is correct |
54 |
Correct |
63 ms |
14124 KB |
Output is correct |
55 |
Correct |
66 ms |
14160 KB |
Output is correct |
56 |
Correct |
62 ms |
14104 KB |
Output is correct |
57 |
Correct |
62 ms |
14136 KB |
Output is correct |
58 |
Correct |
71 ms |
14120 KB |
Output is correct |
59 |
Correct |
65 ms |
14156 KB |
Output is correct |
60 |
Correct |
63 ms |
14136 KB |
Output is correct |
61 |
Correct |
66 ms |
14184 KB |
Output is correct |
62 |
Correct |
70 ms |
14116 KB |
Output is correct |
63 |
Correct |
68 ms |
14112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
8404 KB |
Output is correct |
2 |
Correct |
42 ms |
8388 KB |
Output is correct |
3 |
Correct |
44 ms |
8388 KB |
Output is correct |
4 |
Correct |
52 ms |
8380 KB |
Output is correct |
5 |
Correct |
51 ms |
8396 KB |
Output is correct |
6 |
Correct |
49 ms |
8356 KB |
Output is correct |
7 |
Correct |
44 ms |
8444 KB |
Output is correct |
8 |
Correct |
44 ms |
8360 KB |
Output is correct |
9 |
Correct |
44 ms |
8392 KB |
Output is correct |
10 |
Correct |
44 ms |
8404 KB |
Output is correct |
11 |
Correct |
59 ms |
8332 KB |
Output is correct |
12 |
Correct |
49 ms |
8380 KB |
Output is correct |
13 |
Correct |
43 ms |
8396 KB |
Output is correct |
14 |
Correct |
43 ms |
8332 KB |
Output is correct |
15 |
Correct |
44 ms |
8396 KB |
Output is correct |
16 |
Correct |
57 ms |
8408 KB |
Output is correct |
17 |
Correct |
51 ms |
8404 KB |
Output is correct |
18 |
Correct |
44 ms |
8404 KB |
Output is correct |
19 |
Correct |
52 ms |
8612 KB |
Output is correct |
20 |
Correct |
47 ms |
8396 KB |
Output is correct |
21 |
Correct |
43 ms |
8368 KB |
Output is correct |
22 |
Correct |
69 ms |
9648 KB |
Output is correct |
23 |
Correct |
53 ms |
9624 KB |
Output is correct |
24 |
Correct |
46 ms |
9608 KB |
Output is correct |
25 |
Correct |
46 ms |
9648 KB |
Output is correct |
26 |
Correct |
48 ms |
9576 KB |
Output is correct |
27 |
Correct |
49 ms |
9596 KB |
Output is correct |
28 |
Correct |
53 ms |
9648 KB |
Output is correct |
29 |
Correct |
47 ms |
9676 KB |
Output is correct |
30 |
Correct |
49 ms |
9580 KB |
Output is correct |
31 |
Correct |
47 ms |
9580 KB |
Output is correct |
32 |
Correct |
45 ms |
9660 KB |
Output is correct |
33 |
Correct |
52 ms |
9648 KB |
Output is correct |
34 |
Correct |
60 ms |
9568 KB |
Output is correct |
35 |
Correct |
45 ms |
9596 KB |
Output is correct |
36 |
Correct |
58 ms |
9680 KB |
Output is correct |
37 |
Correct |
47 ms |
9624 KB |
Output is correct |
38 |
Correct |
53 ms |
9624 KB |
Output is correct |
39 |
Correct |
67 ms |
9692 KB |
Output is correct |
40 |
Correct |
58 ms |
9564 KB |
Output is correct |
41 |
Correct |
50 ms |
9604 KB |
Output is correct |
42 |
Correct |
46 ms |
9676 KB |
Output is correct |
43 |
Correct |
67 ms |
14152 KB |
Output is correct |
44 |
Correct |
70 ms |
14188 KB |
Output is correct |
45 |
Correct |
66 ms |
14144 KB |
Output is correct |
46 |
Correct |
62 ms |
14124 KB |
Output is correct |
47 |
Correct |
64 ms |
14196 KB |
Output is correct |
48 |
Correct |
69 ms |
14128 KB |
Output is correct |
49 |
Correct |
62 ms |
14076 KB |
Output is correct |
50 |
Correct |
67 ms |
14192 KB |
Output is correct |
51 |
Correct |
67 ms |
14184 KB |
Output is correct |
52 |
Correct |
72 ms |
14096 KB |
Output is correct |
53 |
Correct |
75 ms |
14188 KB |
Output is correct |
54 |
Correct |
63 ms |
14124 KB |
Output is correct |
55 |
Correct |
66 ms |
14160 KB |
Output is correct |
56 |
Correct |
62 ms |
14104 KB |
Output is correct |
57 |
Correct |
62 ms |
14136 KB |
Output is correct |
58 |
Correct |
71 ms |
14120 KB |
Output is correct |
59 |
Correct |
65 ms |
14156 KB |
Output is correct |
60 |
Correct |
63 ms |
14136 KB |
Output is correct |
61 |
Correct |
66 ms |
14184 KB |
Output is correct |
62 |
Correct |
70 ms |
14116 KB |
Output is correct |
63 |
Correct |
68 ms |
14112 KB |
Output is correct |
64 |
Correct |
242 ms |
37640 KB |
Output is correct |
65 |
Correct |
284 ms |
38384 KB |
Output is correct |
66 |
Correct |
241 ms |
38376 KB |
Output is correct |
67 |
Correct |
280 ms |
38384 KB |
Output is correct |
68 |
Correct |
240 ms |
38312 KB |
Output is correct |
69 |
Correct |
242 ms |
38276 KB |
Output is correct |
70 |
Correct |
245 ms |
38396 KB |
Output is correct |
71 |
Correct |
255 ms |
38380 KB |
Output is correct |
72 |
Correct |
233 ms |
38444 KB |
Output is correct |
73 |
Correct |
244 ms |
38316 KB |
Output is correct |
74 |
Correct |
234 ms |
38380 KB |
Output is correct |
75 |
Correct |
256 ms |
38376 KB |
Output is correct |
76 |
Correct |
235 ms |
38316 KB |
Output is correct |
77 |
Correct |
253 ms |
38268 KB |
Output is correct |
78 |
Correct |
247 ms |
38504 KB |
Output is correct |
79 |
Correct |
260 ms |
38392 KB |
Output is correct |
80 |
Correct |
243 ms |
38336 KB |
Output is correct |
81 |
Correct |
249 ms |
38380 KB |
Output is correct |
82 |
Correct |
235 ms |
38348 KB |
Output is correct |
83 |
Correct |
239 ms |
38308 KB |
Output is correct |
84 |
Correct |
232 ms |
38372 KB |
Output is correct |