#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int ALP = 62;
const int MOD = 998244353;
unordered_set<string> s[15];
int32_t main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
for(int i = 1; i <= n; i++){
string cur; cin >> cur;
s[cur.size()].emplace(cur);
reverse(cur.begin(), cur.end());
s[cur.size()].emplace(cur);
}
auto getId = [&](char c)
{
if(c <= '9') return c - '0';
if(c <= 'Z') return ('9' - '0' + 1) + c - 'A';
return ('9' - '0' + 1) + ('Z' - 'A') + 1 + c - 'a';
};
auto solve = [&](int tam)
{
int dp[ALP][ALP][ALP] = { 0 };
int freq[ALP][ALP] = { 0 };
for(auto x : s[tam]){
int i = getId(x[0]), j = getId(x.back());
freq[i][j]++;
}
for(int a = 0; a < ALP; a++)
for(int b = 0; b < ALP; b++)
for(int c = 0; c < ALP; c++)
for(int i = 0; i < ALP; i++)
dp[a][b][c] = (dp[a][b][c] + (freq[a][i] * freq[b][i] * freq[c][i]) % MOD) % MOD;
int ret = 0;
for(int a = 0; a < ALP; a++){
for(int b = 0; b < ALP; b++){
for(int c = 0; c < ALP; c++){
for(int d = 0; d < ALP; d++){
int curAdd = 1;
curAdd = (curAdd * dp[a][b][c]) % MOD;
curAdd = (curAdd * dp[b][c][d]) % MOD;
curAdd = (curAdd * dp[a][b][d]) % MOD;
curAdd = (curAdd * dp[a][c][d]) % MOD;
ret += curAdd;
}
}
}
}
return ret;
};
int ans = 0;
for(int i = 1; i <= 10; i++){
if(s[i].empty()) continue;
ans = (ans + solve(i)) % MOD;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
964 ms |
16436 KB |
Output is correct |
2 |
Correct |
968 ms |
16428 KB |
Output is correct |
3 |
Correct |
953 ms |
16436 KB |
Output is correct |
4 |
Correct |
981 ms |
16420 KB |
Output is correct |
5 |
Correct |
963 ms |
16436 KB |
Output is correct |
6 |
Correct |
963 ms |
16428 KB |
Output is correct |
7 |
Correct |
1010 ms |
16436 KB |
Output is correct |
8 |
Correct |
995 ms |
16436 KB |
Output is correct |
9 |
Correct |
957 ms |
16408 KB |
Output is correct |
10 |
Correct |
965 ms |
16432 KB |
Output is correct |
11 |
Correct |
979 ms |
16320 KB |
Output is correct |
12 |
Correct |
949 ms |
16408 KB |
Output is correct |
13 |
Correct |
996 ms |
16444 KB |
Output is correct |
14 |
Correct |
955 ms |
16428 KB |
Output is correct |
15 |
Correct |
970 ms |
16436 KB |
Output is correct |
16 |
Correct |
981 ms |
16424 KB |
Output is correct |
17 |
Correct |
958 ms |
16428 KB |
Output is correct |
18 |
Correct |
1006 ms |
16424 KB |
Output is correct |
19 |
Correct |
975 ms |
16420 KB |
Output is correct |
20 |
Correct |
967 ms |
16440 KB |
Output is correct |
21 |
Correct |
988 ms |
16424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
964 ms |
16436 KB |
Output is correct |
2 |
Correct |
968 ms |
16428 KB |
Output is correct |
3 |
Correct |
953 ms |
16436 KB |
Output is correct |
4 |
Correct |
981 ms |
16420 KB |
Output is correct |
5 |
Correct |
963 ms |
16436 KB |
Output is correct |
6 |
Correct |
963 ms |
16428 KB |
Output is correct |
7 |
Correct |
1010 ms |
16436 KB |
Output is correct |
8 |
Correct |
995 ms |
16436 KB |
Output is correct |
9 |
Correct |
957 ms |
16408 KB |
Output is correct |
10 |
Correct |
965 ms |
16432 KB |
Output is correct |
11 |
Correct |
979 ms |
16320 KB |
Output is correct |
12 |
Correct |
949 ms |
16408 KB |
Output is correct |
13 |
Correct |
996 ms |
16444 KB |
Output is correct |
14 |
Correct |
955 ms |
16428 KB |
Output is correct |
15 |
Correct |
970 ms |
16436 KB |
Output is correct |
16 |
Correct |
981 ms |
16424 KB |
Output is correct |
17 |
Correct |
958 ms |
16428 KB |
Output is correct |
18 |
Correct |
1006 ms |
16424 KB |
Output is correct |
19 |
Correct |
975 ms |
16420 KB |
Output is correct |
20 |
Correct |
967 ms |
16440 KB |
Output is correct |
21 |
Correct |
988 ms |
16424 KB |
Output is correct |
22 |
Correct |
977 ms |
17476 KB |
Output is correct |
23 |
Correct |
977 ms |
17476 KB |
Output is correct |
24 |
Correct |
1000 ms |
17488 KB |
Output is correct |
25 |
Correct |
996 ms |
17472 KB |
Output is correct |
26 |
Correct |
981 ms |
17488 KB |
Output is correct |
27 |
Correct |
958 ms |
17472 KB |
Output is correct |
28 |
Correct |
954 ms |
17480 KB |
Output is correct |
29 |
Correct |
966 ms |
17484 KB |
Output is correct |
30 |
Correct |
960 ms |
17476 KB |
Output is correct |
31 |
Correct |
993 ms |
17436 KB |
Output is correct |
32 |
Correct |
960 ms |
17460 KB |
Output is correct |
33 |
Correct |
989 ms |
17472 KB |
Output is correct |
34 |
Correct |
993 ms |
17476 KB |
Output is correct |
35 |
Correct |
1041 ms |
17472 KB |
Output is correct |
36 |
Correct |
1000 ms |
17476 KB |
Output is correct |
37 |
Correct |
1036 ms |
17476 KB |
Output is correct |
38 |
Correct |
1034 ms |
17480 KB |
Output is correct |
39 |
Correct |
974 ms |
17476 KB |
Output is correct |
40 |
Correct |
1022 ms |
17476 KB |
Output is correct |
41 |
Correct |
1008 ms |
17472 KB |
Output is correct |
42 |
Correct |
1037 ms |
17484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
964 ms |
16436 KB |
Output is correct |
2 |
Correct |
968 ms |
16428 KB |
Output is correct |
3 |
Correct |
953 ms |
16436 KB |
Output is correct |
4 |
Correct |
981 ms |
16420 KB |
Output is correct |
5 |
Correct |
963 ms |
16436 KB |
Output is correct |
6 |
Correct |
963 ms |
16428 KB |
Output is correct |
7 |
Correct |
1010 ms |
16436 KB |
Output is correct |
8 |
Correct |
995 ms |
16436 KB |
Output is correct |
9 |
Correct |
957 ms |
16408 KB |
Output is correct |
10 |
Correct |
965 ms |
16432 KB |
Output is correct |
11 |
Correct |
979 ms |
16320 KB |
Output is correct |
12 |
Correct |
949 ms |
16408 KB |
Output is correct |
13 |
Correct |
996 ms |
16444 KB |
Output is correct |
14 |
Correct |
955 ms |
16428 KB |
Output is correct |
15 |
Correct |
970 ms |
16436 KB |
Output is correct |
16 |
Correct |
981 ms |
16424 KB |
Output is correct |
17 |
Correct |
958 ms |
16428 KB |
Output is correct |
18 |
Correct |
1006 ms |
16424 KB |
Output is correct |
19 |
Correct |
975 ms |
16420 KB |
Output is correct |
20 |
Correct |
967 ms |
16440 KB |
Output is correct |
21 |
Correct |
988 ms |
16424 KB |
Output is correct |
22 |
Correct |
977 ms |
17476 KB |
Output is correct |
23 |
Correct |
977 ms |
17476 KB |
Output is correct |
24 |
Correct |
1000 ms |
17488 KB |
Output is correct |
25 |
Correct |
996 ms |
17472 KB |
Output is correct |
26 |
Correct |
981 ms |
17488 KB |
Output is correct |
27 |
Correct |
958 ms |
17472 KB |
Output is correct |
28 |
Correct |
954 ms |
17480 KB |
Output is correct |
29 |
Correct |
966 ms |
17484 KB |
Output is correct |
30 |
Correct |
960 ms |
17476 KB |
Output is correct |
31 |
Correct |
993 ms |
17436 KB |
Output is correct |
32 |
Correct |
960 ms |
17460 KB |
Output is correct |
33 |
Correct |
989 ms |
17472 KB |
Output is correct |
34 |
Correct |
993 ms |
17476 KB |
Output is correct |
35 |
Correct |
1041 ms |
17472 KB |
Output is correct |
36 |
Correct |
1000 ms |
17476 KB |
Output is correct |
37 |
Correct |
1036 ms |
17476 KB |
Output is correct |
38 |
Correct |
1034 ms |
17480 KB |
Output is correct |
39 |
Correct |
974 ms |
17476 KB |
Output is correct |
40 |
Correct |
1022 ms |
17476 KB |
Output is correct |
41 |
Correct |
1008 ms |
17472 KB |
Output is correct |
42 |
Correct |
1037 ms |
17484 KB |
Output is correct |
43 |
Correct |
971 ms |
17752 KB |
Output is correct |
44 |
Correct |
994 ms |
17752 KB |
Output is correct |
45 |
Correct |
1014 ms |
17744 KB |
Output is correct |
46 |
Correct |
1010 ms |
17740 KB |
Output is correct |
47 |
Correct |
980 ms |
17744 KB |
Output is correct |
48 |
Correct |
1022 ms |
17744 KB |
Output is correct |
49 |
Correct |
1002 ms |
17716 KB |
Output is correct |
50 |
Correct |
989 ms |
17756 KB |
Output is correct |
51 |
Correct |
966 ms |
17696 KB |
Output is correct |
52 |
Correct |
971 ms |
17732 KB |
Output is correct |
53 |
Correct |
976 ms |
17760 KB |
Output is correct |
54 |
Correct |
988 ms |
17748 KB |
Output is correct |
55 |
Correct |
971 ms |
17736 KB |
Output is correct |
56 |
Correct |
954 ms |
17756 KB |
Output is correct |
57 |
Correct |
979 ms |
17768 KB |
Output is correct |
58 |
Correct |
985 ms |
17744 KB |
Output is correct |
59 |
Correct |
992 ms |
17740 KB |
Output is correct |
60 |
Correct |
970 ms |
17736 KB |
Output is correct |
61 |
Correct |
998 ms |
17732 KB |
Output is correct |
62 |
Correct |
969 ms |
17732 KB |
Output is correct |
63 |
Correct |
976 ms |
17736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
964 ms |
16436 KB |
Output is correct |
2 |
Correct |
968 ms |
16428 KB |
Output is correct |
3 |
Correct |
953 ms |
16436 KB |
Output is correct |
4 |
Correct |
981 ms |
16420 KB |
Output is correct |
5 |
Correct |
963 ms |
16436 KB |
Output is correct |
6 |
Correct |
963 ms |
16428 KB |
Output is correct |
7 |
Correct |
1010 ms |
16436 KB |
Output is correct |
8 |
Correct |
995 ms |
16436 KB |
Output is correct |
9 |
Correct |
957 ms |
16408 KB |
Output is correct |
10 |
Correct |
965 ms |
16432 KB |
Output is correct |
11 |
Correct |
979 ms |
16320 KB |
Output is correct |
12 |
Correct |
949 ms |
16408 KB |
Output is correct |
13 |
Correct |
996 ms |
16444 KB |
Output is correct |
14 |
Correct |
955 ms |
16428 KB |
Output is correct |
15 |
Correct |
970 ms |
16436 KB |
Output is correct |
16 |
Correct |
981 ms |
16424 KB |
Output is correct |
17 |
Correct |
958 ms |
16428 KB |
Output is correct |
18 |
Correct |
1006 ms |
16424 KB |
Output is correct |
19 |
Correct |
975 ms |
16420 KB |
Output is correct |
20 |
Correct |
967 ms |
16440 KB |
Output is correct |
21 |
Correct |
988 ms |
16424 KB |
Output is correct |
22 |
Correct |
977 ms |
17476 KB |
Output is correct |
23 |
Correct |
977 ms |
17476 KB |
Output is correct |
24 |
Correct |
1000 ms |
17488 KB |
Output is correct |
25 |
Correct |
996 ms |
17472 KB |
Output is correct |
26 |
Correct |
981 ms |
17488 KB |
Output is correct |
27 |
Correct |
958 ms |
17472 KB |
Output is correct |
28 |
Correct |
954 ms |
17480 KB |
Output is correct |
29 |
Correct |
966 ms |
17484 KB |
Output is correct |
30 |
Correct |
960 ms |
17476 KB |
Output is correct |
31 |
Correct |
993 ms |
17436 KB |
Output is correct |
32 |
Correct |
960 ms |
17460 KB |
Output is correct |
33 |
Correct |
989 ms |
17472 KB |
Output is correct |
34 |
Correct |
993 ms |
17476 KB |
Output is correct |
35 |
Correct |
1041 ms |
17472 KB |
Output is correct |
36 |
Correct |
1000 ms |
17476 KB |
Output is correct |
37 |
Correct |
1036 ms |
17476 KB |
Output is correct |
38 |
Correct |
1034 ms |
17480 KB |
Output is correct |
39 |
Correct |
974 ms |
17476 KB |
Output is correct |
40 |
Correct |
1022 ms |
17476 KB |
Output is correct |
41 |
Correct |
1008 ms |
17472 KB |
Output is correct |
42 |
Correct |
1037 ms |
17484 KB |
Output is correct |
43 |
Correct |
971 ms |
17752 KB |
Output is correct |
44 |
Correct |
994 ms |
17752 KB |
Output is correct |
45 |
Correct |
1014 ms |
17744 KB |
Output is correct |
46 |
Correct |
1010 ms |
17740 KB |
Output is correct |
47 |
Correct |
980 ms |
17744 KB |
Output is correct |
48 |
Correct |
1022 ms |
17744 KB |
Output is correct |
49 |
Correct |
1002 ms |
17716 KB |
Output is correct |
50 |
Correct |
989 ms |
17756 KB |
Output is correct |
51 |
Correct |
966 ms |
17696 KB |
Output is correct |
52 |
Correct |
971 ms |
17732 KB |
Output is correct |
53 |
Correct |
976 ms |
17760 KB |
Output is correct |
54 |
Correct |
988 ms |
17748 KB |
Output is correct |
55 |
Correct |
971 ms |
17736 KB |
Output is correct |
56 |
Correct |
954 ms |
17756 KB |
Output is correct |
57 |
Correct |
979 ms |
17768 KB |
Output is correct |
58 |
Correct |
985 ms |
17744 KB |
Output is correct |
59 |
Correct |
992 ms |
17740 KB |
Output is correct |
60 |
Correct |
970 ms |
17736 KB |
Output is correct |
61 |
Correct |
998 ms |
17732 KB |
Output is correct |
62 |
Correct |
969 ms |
17732 KB |
Output is correct |
63 |
Correct |
976 ms |
17736 KB |
Output is correct |
64 |
Correct |
965 ms |
18084 KB |
Output is correct |
65 |
Correct |
975 ms |
18084 KB |
Output is correct |
66 |
Correct |
986 ms |
18096 KB |
Output is correct |
67 |
Correct |
955 ms |
18088 KB |
Output is correct |
68 |
Correct |
974 ms |
18092 KB |
Output is correct |
69 |
Correct |
972 ms |
18088 KB |
Output is correct |
70 |
Correct |
959 ms |
18092 KB |
Output is correct |
71 |
Correct |
965 ms |
17996 KB |
Output is correct |
72 |
Correct |
965 ms |
18100 KB |
Output is correct |
73 |
Correct |
965 ms |
18092 KB |
Output is correct |
74 |
Correct |
962 ms |
18088 KB |
Output is correct |
75 |
Correct |
967 ms |
18080 KB |
Output is correct |
76 |
Correct |
975 ms |
18084 KB |
Output is correct |
77 |
Correct |
969 ms |
18088 KB |
Output is correct |
78 |
Correct |
960 ms |
18088 KB |
Output is correct |
79 |
Correct |
962 ms |
18124 KB |
Output is correct |
80 |
Correct |
967 ms |
18096 KB |
Output is correct |
81 |
Correct |
981 ms |
18092 KB |
Output is correct |
82 |
Correct |
979 ms |
18092 KB |
Output is correct |
83 |
Correct |
961 ms |
18096 KB |
Output is correct |
84 |
Correct |
955 ms |
18088 KB |
Output is correct |