//IN THE NAME OF GOD
#include<bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
#define endl '\n'
#define F first
#define S second
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define pb push_back
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define file_io freopen("input.in" , "r" , stdin) ; freopen("output.out" , "w" , stdout);
using namespace std;
typedef long long ll;
typedef long double dll;
const int N = 62, NN = 11, mod = 998244353;
int hav[NN][N][N], havi[NN], can[NN][N], dp[N][N][N];
vector<string> vec[NN];
inline int f(char c){
if (int(c) <= 57) return (int(c)-48);
else if (int(c) <= 90) return (int(c)-65+10);
else return (int(c)-97+36);
}
inline char ff(int x){
if (x < 10) return char(x+48);
else if (x < 36) return char(x+65-10);
else return char(x+97-36);
}
int32_t main(){
fast_io;
int n; cin >> n;
string s, ss; int siz;
for(int i=1; i<=n; i++){
cin >> s; ss = s;
siz = s.size();
havi[siz] = 1;
vec[siz].pb(s);
reverse(all(ss));
if (ss != s) vec[siz].pb(ss);
}
for(int i=3; i<=10; i++){
sort(all(vec[i]));
for(int j=0; j<int(vec[i].size()); j++){
if (j != 0 && vec[i][j] == vec[i][j-1]) continue;
can[i][f(vec[i][j][0])] = 1;
hav[i][f(vec[i][j][0])][f(vec[i][j].back())]++;
}
}
ll ans = 0, tmp;
for(int i=3; i<=10; i++){
if (!havi[i]) continue;
memset(dp,0,sizeof dp);
for(int s1 = 0; s1<N; s1++){
if (!can[i][s1]) continue;
for(int s2 = 0; s2<N; s2++){
if (!can[i][s2]) continue;
for(int s3 = 0; s3 < N; s3++){
if (!can[i][s3]) continue;
for(int put=0; put<N; put++) dp[s1][s2][s3] = (dp[s1][s2][s3]+1ll*hav[i][s1][put]*hav[i][s2][put]*hav[i][s3][put]%mod)%mod;
}
}
}
for(int s1 = 0; s1<N; s1++){
if (!can[i][s1]) continue;
for(int s2=0; s2<N; s2++){
if (!can[i][s2]) continue;
for(int s3=0; s3<N; s3++){
if (!can[i][s3]) continue;
for(int s4=0; s4<N; s4++){
if (!can[i][s4]) continue;
tmp = 1ll*dp[s1][s2][s3]*dp[s1][s2][s4]%mod*dp[s1][s3][s4]%mod*dp[s2][s3][s4]%mod;
ans = (ans+tmp)%mod;
}
}
}
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
8160 KB |
Output is correct |
2 |
Correct |
44 ms |
7840 KB |
Output is correct |
3 |
Correct |
43 ms |
7820 KB |
Output is correct |
4 |
Correct |
43 ms |
8004 KB |
Output is correct |
5 |
Correct |
42 ms |
8016 KB |
Output is correct |
6 |
Correct |
43 ms |
8208 KB |
Output is correct |
7 |
Correct |
42 ms |
7932 KB |
Output is correct |
8 |
Correct |
45 ms |
8104 KB |
Output is correct |
9 |
Correct |
42 ms |
7896 KB |
Output is correct |
10 |
Correct |
43 ms |
7964 KB |
Output is correct |
11 |
Correct |
43 ms |
8056 KB |
Output is correct |
12 |
Correct |
42 ms |
7928 KB |
Output is correct |
13 |
Correct |
42 ms |
7820 KB |
Output is correct |
14 |
Correct |
43 ms |
7696 KB |
Output is correct |
15 |
Correct |
54 ms |
7920 KB |
Output is correct |
16 |
Correct |
43 ms |
7868 KB |
Output is correct |
17 |
Correct |
42 ms |
7892 KB |
Output is correct |
18 |
Correct |
42 ms |
7836 KB |
Output is correct |
19 |
Correct |
43 ms |
7908 KB |
Output is correct |
20 |
Correct |
42 ms |
7916 KB |
Output is correct |
21 |
Correct |
42 ms |
7924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
8160 KB |
Output is correct |
2 |
Correct |
44 ms |
7840 KB |
Output is correct |
3 |
Correct |
43 ms |
7820 KB |
Output is correct |
4 |
Correct |
43 ms |
8004 KB |
Output is correct |
5 |
Correct |
42 ms |
8016 KB |
Output is correct |
6 |
Correct |
43 ms |
8208 KB |
Output is correct |
7 |
Correct |
42 ms |
7932 KB |
Output is correct |
8 |
Correct |
45 ms |
8104 KB |
Output is correct |
9 |
Correct |
42 ms |
7896 KB |
Output is correct |
10 |
Correct |
43 ms |
7964 KB |
Output is correct |
11 |
Correct |
43 ms |
8056 KB |
Output is correct |
12 |
Correct |
42 ms |
7928 KB |
Output is correct |
13 |
Correct |
42 ms |
7820 KB |
Output is correct |
14 |
Correct |
43 ms |
7696 KB |
Output is correct |
15 |
Correct |
54 ms |
7920 KB |
Output is correct |
16 |
Correct |
43 ms |
7868 KB |
Output is correct |
17 |
Correct |
42 ms |
7892 KB |
Output is correct |
18 |
Correct |
42 ms |
7836 KB |
Output is correct |
19 |
Correct |
43 ms |
7908 KB |
Output is correct |
20 |
Correct |
42 ms |
7916 KB |
Output is correct |
21 |
Correct |
42 ms |
7924 KB |
Output is correct |
22 |
Correct |
55 ms |
7836 KB |
Output is correct |
23 |
Correct |
52 ms |
7760 KB |
Output is correct |
24 |
Correct |
54 ms |
7680 KB |
Output is correct |
25 |
Correct |
52 ms |
7912 KB |
Output is correct |
26 |
Correct |
53 ms |
7860 KB |
Output is correct |
27 |
Correct |
53 ms |
7960 KB |
Output is correct |
28 |
Correct |
52 ms |
7664 KB |
Output is correct |
29 |
Correct |
52 ms |
7860 KB |
Output is correct |
30 |
Correct |
54 ms |
7828 KB |
Output is correct |
31 |
Correct |
51 ms |
7868 KB |
Output is correct |
32 |
Correct |
52 ms |
7760 KB |
Output is correct |
33 |
Correct |
52 ms |
7676 KB |
Output is correct |
34 |
Correct |
52 ms |
7780 KB |
Output is correct |
35 |
Correct |
52 ms |
7720 KB |
Output is correct |
36 |
Correct |
53 ms |
7828 KB |
Output is correct |
37 |
Correct |
52 ms |
7776 KB |
Output is correct |
38 |
Correct |
52 ms |
7932 KB |
Output is correct |
39 |
Correct |
51 ms |
7852 KB |
Output is correct |
40 |
Correct |
52 ms |
7736 KB |
Output is correct |
41 |
Correct |
52 ms |
7828 KB |
Output is correct |
42 |
Correct |
52 ms |
7628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
8160 KB |
Output is correct |
2 |
Correct |
44 ms |
7840 KB |
Output is correct |
3 |
Correct |
43 ms |
7820 KB |
Output is correct |
4 |
Correct |
43 ms |
8004 KB |
Output is correct |
5 |
Correct |
42 ms |
8016 KB |
Output is correct |
6 |
Correct |
43 ms |
8208 KB |
Output is correct |
7 |
Correct |
42 ms |
7932 KB |
Output is correct |
8 |
Correct |
45 ms |
8104 KB |
Output is correct |
9 |
Correct |
42 ms |
7896 KB |
Output is correct |
10 |
Correct |
43 ms |
7964 KB |
Output is correct |
11 |
Correct |
43 ms |
8056 KB |
Output is correct |
12 |
Correct |
42 ms |
7928 KB |
Output is correct |
13 |
Correct |
42 ms |
7820 KB |
Output is correct |
14 |
Correct |
43 ms |
7696 KB |
Output is correct |
15 |
Correct |
54 ms |
7920 KB |
Output is correct |
16 |
Correct |
43 ms |
7868 KB |
Output is correct |
17 |
Correct |
42 ms |
7892 KB |
Output is correct |
18 |
Correct |
42 ms |
7836 KB |
Output is correct |
19 |
Correct |
43 ms |
7908 KB |
Output is correct |
20 |
Correct |
42 ms |
7916 KB |
Output is correct |
21 |
Correct |
42 ms |
7924 KB |
Output is correct |
22 |
Correct |
55 ms |
7836 KB |
Output is correct |
23 |
Correct |
52 ms |
7760 KB |
Output is correct |
24 |
Correct |
54 ms |
7680 KB |
Output is correct |
25 |
Correct |
52 ms |
7912 KB |
Output is correct |
26 |
Correct |
53 ms |
7860 KB |
Output is correct |
27 |
Correct |
53 ms |
7960 KB |
Output is correct |
28 |
Correct |
52 ms |
7664 KB |
Output is correct |
29 |
Correct |
52 ms |
7860 KB |
Output is correct |
30 |
Correct |
54 ms |
7828 KB |
Output is correct |
31 |
Correct |
51 ms |
7868 KB |
Output is correct |
32 |
Correct |
52 ms |
7760 KB |
Output is correct |
33 |
Correct |
52 ms |
7676 KB |
Output is correct |
34 |
Correct |
52 ms |
7780 KB |
Output is correct |
35 |
Correct |
52 ms |
7720 KB |
Output is correct |
36 |
Correct |
53 ms |
7828 KB |
Output is correct |
37 |
Correct |
52 ms |
7776 KB |
Output is correct |
38 |
Correct |
52 ms |
7932 KB |
Output is correct |
39 |
Correct |
51 ms |
7852 KB |
Output is correct |
40 |
Correct |
52 ms |
7736 KB |
Output is correct |
41 |
Correct |
52 ms |
7828 KB |
Output is correct |
42 |
Correct |
52 ms |
7628 KB |
Output is correct |
43 |
Correct |
154 ms |
7876 KB |
Output is correct |
44 |
Correct |
154 ms |
7916 KB |
Output is correct |
45 |
Correct |
163 ms |
7948 KB |
Output is correct |
46 |
Correct |
154 ms |
7996 KB |
Output is correct |
47 |
Correct |
155 ms |
7816 KB |
Output is correct |
48 |
Correct |
159 ms |
8164 KB |
Output is correct |
49 |
Correct |
160 ms |
7888 KB |
Output is correct |
50 |
Correct |
157 ms |
8088 KB |
Output is correct |
51 |
Correct |
159 ms |
8212 KB |
Output is correct |
52 |
Correct |
155 ms |
7684 KB |
Output is correct |
53 |
Correct |
155 ms |
7856 KB |
Output is correct |
54 |
Correct |
156 ms |
8172 KB |
Output is correct |
55 |
Correct |
162 ms |
8300 KB |
Output is correct |
56 |
Correct |
168 ms |
7916 KB |
Output is correct |
57 |
Correct |
154 ms |
8088 KB |
Output is correct |
58 |
Correct |
154 ms |
8124 KB |
Output is correct |
59 |
Correct |
159 ms |
8256 KB |
Output is correct |
60 |
Correct |
163 ms |
8132 KB |
Output is correct |
61 |
Correct |
158 ms |
7916 KB |
Output is correct |
62 |
Correct |
155 ms |
7944 KB |
Output is correct |
63 |
Correct |
154 ms |
8100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
8160 KB |
Output is correct |
2 |
Correct |
44 ms |
7840 KB |
Output is correct |
3 |
Correct |
43 ms |
7820 KB |
Output is correct |
4 |
Correct |
43 ms |
8004 KB |
Output is correct |
5 |
Correct |
42 ms |
8016 KB |
Output is correct |
6 |
Correct |
43 ms |
8208 KB |
Output is correct |
7 |
Correct |
42 ms |
7932 KB |
Output is correct |
8 |
Correct |
45 ms |
8104 KB |
Output is correct |
9 |
Correct |
42 ms |
7896 KB |
Output is correct |
10 |
Correct |
43 ms |
7964 KB |
Output is correct |
11 |
Correct |
43 ms |
8056 KB |
Output is correct |
12 |
Correct |
42 ms |
7928 KB |
Output is correct |
13 |
Correct |
42 ms |
7820 KB |
Output is correct |
14 |
Correct |
43 ms |
7696 KB |
Output is correct |
15 |
Correct |
54 ms |
7920 KB |
Output is correct |
16 |
Correct |
43 ms |
7868 KB |
Output is correct |
17 |
Correct |
42 ms |
7892 KB |
Output is correct |
18 |
Correct |
42 ms |
7836 KB |
Output is correct |
19 |
Correct |
43 ms |
7908 KB |
Output is correct |
20 |
Correct |
42 ms |
7916 KB |
Output is correct |
21 |
Correct |
42 ms |
7924 KB |
Output is correct |
22 |
Correct |
55 ms |
7836 KB |
Output is correct |
23 |
Correct |
52 ms |
7760 KB |
Output is correct |
24 |
Correct |
54 ms |
7680 KB |
Output is correct |
25 |
Correct |
52 ms |
7912 KB |
Output is correct |
26 |
Correct |
53 ms |
7860 KB |
Output is correct |
27 |
Correct |
53 ms |
7960 KB |
Output is correct |
28 |
Correct |
52 ms |
7664 KB |
Output is correct |
29 |
Correct |
52 ms |
7860 KB |
Output is correct |
30 |
Correct |
54 ms |
7828 KB |
Output is correct |
31 |
Correct |
51 ms |
7868 KB |
Output is correct |
32 |
Correct |
52 ms |
7760 KB |
Output is correct |
33 |
Correct |
52 ms |
7676 KB |
Output is correct |
34 |
Correct |
52 ms |
7780 KB |
Output is correct |
35 |
Correct |
52 ms |
7720 KB |
Output is correct |
36 |
Correct |
53 ms |
7828 KB |
Output is correct |
37 |
Correct |
52 ms |
7776 KB |
Output is correct |
38 |
Correct |
52 ms |
7932 KB |
Output is correct |
39 |
Correct |
51 ms |
7852 KB |
Output is correct |
40 |
Correct |
52 ms |
7736 KB |
Output is correct |
41 |
Correct |
52 ms |
7828 KB |
Output is correct |
42 |
Correct |
52 ms |
7628 KB |
Output is correct |
43 |
Correct |
154 ms |
7876 KB |
Output is correct |
44 |
Correct |
154 ms |
7916 KB |
Output is correct |
45 |
Correct |
163 ms |
7948 KB |
Output is correct |
46 |
Correct |
154 ms |
7996 KB |
Output is correct |
47 |
Correct |
155 ms |
7816 KB |
Output is correct |
48 |
Correct |
159 ms |
8164 KB |
Output is correct |
49 |
Correct |
160 ms |
7888 KB |
Output is correct |
50 |
Correct |
157 ms |
8088 KB |
Output is correct |
51 |
Correct |
159 ms |
8212 KB |
Output is correct |
52 |
Correct |
155 ms |
7684 KB |
Output is correct |
53 |
Correct |
155 ms |
7856 KB |
Output is correct |
54 |
Correct |
156 ms |
8172 KB |
Output is correct |
55 |
Correct |
162 ms |
8300 KB |
Output is correct |
56 |
Correct |
168 ms |
7916 KB |
Output is correct |
57 |
Correct |
154 ms |
8088 KB |
Output is correct |
58 |
Correct |
154 ms |
8124 KB |
Output is correct |
59 |
Correct |
159 ms |
8256 KB |
Output is correct |
60 |
Correct |
163 ms |
8132 KB |
Output is correct |
61 |
Correct |
158 ms |
7916 KB |
Output is correct |
62 |
Correct |
155 ms |
7944 KB |
Output is correct |
63 |
Correct |
154 ms |
8100 KB |
Output is correct |
64 |
Execution timed out |
1165 ms |
7872 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |