/* not my code (obviously i don't code like this wtf) */
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define int long long
map<char, int> mp;
int c[11][62][62][62];
int prod[11][62][62][62];
int aa[11][63][63];
const int mod = 998244353;
const int msq = mod * mod;
inline int mul(int x, int y){
if((x*y)>mod) return x*y%mod;
return x*y;
}
void solve(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int cnt=0;
for(int i='a'; i<='z'; i++) mp[i]=cnt++;
for(int i='A'; i<='Z'; i++) mp[i]=cnt++;
for(int i='0'; i<='9'; i++) mp[i]=cnt++;
int n; cin>>n;
vector<string> s(n), x;
for(auto &i: s){
cin >> i;
string x = i;
reverse(x.begin(), x.end());
if(x<i) i=x;
}
sort(s.begin(), s.end());
for(int i=0; i<n; i++){
if(i==0||s[i]!=s[i-1]) x.push_back(s[i]);
}
memset(aa, 0, sizeof aa);
memset(c, 0, sizeof c);
s=x;
n = s.size();
for(int i=0; i<n; i++){
string x=s[i];
reverse(x.begin(), x.end());
if(x==s[i]) aa[x.size()][mp[x[0]]][mp[x.back()]]++;
else aa[x.size()][mp[x[0]]][mp[x.back()]]++, aa[x.size()][mp[x.back()]][mp[x[0]]]++;
}
for(int i=3; i<=10; i++){
for(int a=0; a<62; a++){
for(int b=a; b<62; b++){
for(int cc=b; cc<62; cc++){
for(int j=0; j<62; j++){
c[i][a][b][cc] += aa[i][a][j] * aa[i][b][j] * aa[i][cc][j];
}
c[i][a][b][cc] %= mod;
}
}
}
}
int ans=0;
for(int i=3; i<=10; i++){
for(int a=0; a<62; a++){
for(int b=a; b<62; b++){
for(int cc=b; cc<62; cc++){
for(int d=cc; d<62; d++){
int val = 0;
if (a != b && b != cc && cc != d) break;
if(d==a) val = 291154603;
else if(d==b) val=166374059;
else if(cc==a) val= 166374059;
else if(b==a && d==cc) val=748683265;
else if(d==cc || b==a) val= 499122177;
else if(cc==b) val = 499122177;
if ((ans += val * mul(mul(c[i][a][b][cc], c[i][a][b][d]), mul(c[i][b][cc][d], c[i][a][cc][d]))) >= msq) ans -= msq;
}
ans %= mod;
}
}
}
for(int a=0; a<62; a++){
for(int b=a + 1; b<62; b++){
for(int cc=b + 1; cc<62; cc++){
for(int d=cc + 1; d<62; d++){
if ((ans += mul(c[i][a][b][cc], c[i][a][b][d]) * mul(c[i][b][cc][d], c[i][a][cc][d])) >= msq) ans -= msq;
}
ans %= mod;
}
}
}
}
ans = (ans * 24) % mod;
cout<<ans<<'\n';
}
signed main() {
int t = 1;
#ifdef galen_colin_local
cin >> t;
#endif
while (t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
29308 KB |
Output is correct |
2 |
Correct |
72 ms |
29900 KB |
Output is correct |
3 |
Correct |
76 ms |
29316 KB |
Output is correct |
4 |
Correct |
74 ms |
29636 KB |
Output is correct |
5 |
Correct |
72 ms |
29300 KB |
Output is correct |
6 |
Correct |
75 ms |
29812 KB |
Output is correct |
7 |
Correct |
72 ms |
29316 KB |
Output is correct |
8 |
Correct |
73 ms |
29380 KB |
Output is correct |
9 |
Correct |
72 ms |
29376 KB |
Output is correct |
10 |
Correct |
76 ms |
29388 KB |
Output is correct |
11 |
Correct |
86 ms |
30144 KB |
Output is correct |
12 |
Correct |
74 ms |
29888 KB |
Output is correct |
13 |
Correct |
76 ms |
30480 KB |
Output is correct |
14 |
Correct |
73 ms |
29632 KB |
Output is correct |
15 |
Correct |
72 ms |
29380 KB |
Output is correct |
16 |
Correct |
72 ms |
29828 KB |
Output is correct |
17 |
Correct |
74 ms |
30404 KB |
Output is correct |
18 |
Correct |
72 ms |
29824 KB |
Output is correct |
19 |
Correct |
79 ms |
30412 KB |
Output is correct |
20 |
Correct |
73 ms |
30148 KB |
Output is correct |
21 |
Correct |
75 ms |
29644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
29308 KB |
Output is correct |
2 |
Correct |
72 ms |
29900 KB |
Output is correct |
3 |
Correct |
76 ms |
29316 KB |
Output is correct |
4 |
Correct |
74 ms |
29636 KB |
Output is correct |
5 |
Correct |
72 ms |
29300 KB |
Output is correct |
6 |
Correct |
75 ms |
29812 KB |
Output is correct |
7 |
Correct |
72 ms |
29316 KB |
Output is correct |
8 |
Correct |
73 ms |
29380 KB |
Output is correct |
9 |
Correct |
72 ms |
29376 KB |
Output is correct |
10 |
Correct |
76 ms |
29388 KB |
Output is correct |
11 |
Correct |
86 ms |
30144 KB |
Output is correct |
12 |
Correct |
74 ms |
29888 KB |
Output is correct |
13 |
Correct |
76 ms |
30480 KB |
Output is correct |
14 |
Correct |
73 ms |
29632 KB |
Output is correct |
15 |
Correct |
72 ms |
29380 KB |
Output is correct |
16 |
Correct |
72 ms |
29828 KB |
Output is correct |
17 |
Correct |
74 ms |
30404 KB |
Output is correct |
18 |
Correct |
72 ms |
29824 KB |
Output is correct |
19 |
Correct |
79 ms |
30412 KB |
Output is correct |
20 |
Correct |
73 ms |
30148 KB |
Output is correct |
21 |
Correct |
75 ms |
29644 KB |
Output is correct |
22 |
Correct |
73 ms |
30600 KB |
Output is correct |
23 |
Correct |
75 ms |
30600 KB |
Output is correct |
24 |
Correct |
76 ms |
29568 KB |
Output is correct |
25 |
Correct |
75 ms |
30404 KB |
Output is correct |
26 |
Correct |
72 ms |
29580 KB |
Output is correct |
27 |
Correct |
72 ms |
30144 KB |
Output is correct |
28 |
Correct |
75 ms |
29888 KB |
Output is correct |
29 |
Correct |
72 ms |
29644 KB |
Output is correct |
30 |
Correct |
72 ms |
29584 KB |
Output is correct |
31 |
Correct |
73 ms |
30144 KB |
Output is correct |
32 |
Correct |
72 ms |
29896 KB |
Output is correct |
33 |
Correct |
76 ms |
30604 KB |
Output is correct |
34 |
Correct |
75 ms |
30660 KB |
Output is correct |
35 |
Correct |
74 ms |
29892 KB |
Output is correct |
36 |
Correct |
73 ms |
29580 KB |
Output is correct |
37 |
Correct |
72 ms |
30152 KB |
Output is correct |
38 |
Correct |
79 ms |
30660 KB |
Output is correct |
39 |
Correct |
76 ms |
29584 KB |
Output is correct |
40 |
Correct |
75 ms |
30148 KB |
Output is correct |
41 |
Correct |
72 ms |
29636 KB |
Output is correct |
42 |
Correct |
74 ms |
29564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
29308 KB |
Output is correct |
2 |
Correct |
72 ms |
29900 KB |
Output is correct |
3 |
Correct |
76 ms |
29316 KB |
Output is correct |
4 |
Correct |
74 ms |
29636 KB |
Output is correct |
5 |
Correct |
72 ms |
29300 KB |
Output is correct |
6 |
Correct |
75 ms |
29812 KB |
Output is correct |
7 |
Correct |
72 ms |
29316 KB |
Output is correct |
8 |
Correct |
73 ms |
29380 KB |
Output is correct |
9 |
Correct |
72 ms |
29376 KB |
Output is correct |
10 |
Correct |
76 ms |
29388 KB |
Output is correct |
11 |
Correct |
86 ms |
30144 KB |
Output is correct |
12 |
Correct |
74 ms |
29888 KB |
Output is correct |
13 |
Correct |
76 ms |
30480 KB |
Output is correct |
14 |
Correct |
73 ms |
29632 KB |
Output is correct |
15 |
Correct |
72 ms |
29380 KB |
Output is correct |
16 |
Correct |
72 ms |
29828 KB |
Output is correct |
17 |
Correct |
74 ms |
30404 KB |
Output is correct |
18 |
Correct |
72 ms |
29824 KB |
Output is correct |
19 |
Correct |
79 ms |
30412 KB |
Output is correct |
20 |
Correct |
73 ms |
30148 KB |
Output is correct |
21 |
Correct |
75 ms |
29644 KB |
Output is correct |
22 |
Correct |
73 ms |
30600 KB |
Output is correct |
23 |
Correct |
75 ms |
30600 KB |
Output is correct |
24 |
Correct |
76 ms |
29568 KB |
Output is correct |
25 |
Correct |
75 ms |
30404 KB |
Output is correct |
26 |
Correct |
72 ms |
29580 KB |
Output is correct |
27 |
Correct |
72 ms |
30144 KB |
Output is correct |
28 |
Correct |
75 ms |
29888 KB |
Output is correct |
29 |
Correct |
72 ms |
29644 KB |
Output is correct |
30 |
Correct |
72 ms |
29584 KB |
Output is correct |
31 |
Correct |
73 ms |
30144 KB |
Output is correct |
32 |
Correct |
72 ms |
29896 KB |
Output is correct |
33 |
Correct |
76 ms |
30604 KB |
Output is correct |
34 |
Correct |
75 ms |
30660 KB |
Output is correct |
35 |
Correct |
74 ms |
29892 KB |
Output is correct |
36 |
Correct |
73 ms |
29580 KB |
Output is correct |
37 |
Correct |
72 ms |
30152 KB |
Output is correct |
38 |
Correct |
79 ms |
30660 KB |
Output is correct |
39 |
Correct |
76 ms |
29584 KB |
Output is correct |
40 |
Correct |
75 ms |
30148 KB |
Output is correct |
41 |
Correct |
72 ms |
29636 KB |
Output is correct |
42 |
Correct |
74 ms |
29564 KB |
Output is correct |
43 |
Correct |
79 ms |
29632 KB |
Output is correct |
44 |
Correct |
86 ms |
29560 KB |
Output is correct |
45 |
Correct |
89 ms |
29564 KB |
Output is correct |
46 |
Correct |
75 ms |
29644 KB |
Output is correct |
47 |
Correct |
74 ms |
29632 KB |
Output is correct |
48 |
Correct |
78 ms |
29636 KB |
Output is correct |
49 |
Correct |
74 ms |
30148 KB |
Output is correct |
50 |
Correct |
75 ms |
29640 KB |
Output is correct |
51 |
Correct |
76 ms |
30144 KB |
Output is correct |
52 |
Correct |
75 ms |
30148 KB |
Output is correct |
53 |
Correct |
75 ms |
30152 KB |
Output is correct |
54 |
Correct |
76 ms |
30404 KB |
Output is correct |
55 |
Correct |
76 ms |
29576 KB |
Output is correct |
56 |
Correct |
79 ms |
30048 KB |
Output is correct |
57 |
Correct |
81 ms |
29568 KB |
Output is correct |
58 |
Correct |
75 ms |
29816 KB |
Output is correct |
59 |
Correct |
75 ms |
29636 KB |
Output is correct |
60 |
Correct |
77 ms |
29632 KB |
Output is correct |
61 |
Correct |
76 ms |
29632 KB |
Output is correct |
62 |
Correct |
75 ms |
30088 KB |
Output is correct |
63 |
Correct |
74 ms |
30400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
29308 KB |
Output is correct |
2 |
Correct |
72 ms |
29900 KB |
Output is correct |
3 |
Correct |
76 ms |
29316 KB |
Output is correct |
4 |
Correct |
74 ms |
29636 KB |
Output is correct |
5 |
Correct |
72 ms |
29300 KB |
Output is correct |
6 |
Correct |
75 ms |
29812 KB |
Output is correct |
7 |
Correct |
72 ms |
29316 KB |
Output is correct |
8 |
Correct |
73 ms |
29380 KB |
Output is correct |
9 |
Correct |
72 ms |
29376 KB |
Output is correct |
10 |
Correct |
76 ms |
29388 KB |
Output is correct |
11 |
Correct |
86 ms |
30144 KB |
Output is correct |
12 |
Correct |
74 ms |
29888 KB |
Output is correct |
13 |
Correct |
76 ms |
30480 KB |
Output is correct |
14 |
Correct |
73 ms |
29632 KB |
Output is correct |
15 |
Correct |
72 ms |
29380 KB |
Output is correct |
16 |
Correct |
72 ms |
29828 KB |
Output is correct |
17 |
Correct |
74 ms |
30404 KB |
Output is correct |
18 |
Correct |
72 ms |
29824 KB |
Output is correct |
19 |
Correct |
79 ms |
30412 KB |
Output is correct |
20 |
Correct |
73 ms |
30148 KB |
Output is correct |
21 |
Correct |
75 ms |
29644 KB |
Output is correct |
22 |
Correct |
73 ms |
30600 KB |
Output is correct |
23 |
Correct |
75 ms |
30600 KB |
Output is correct |
24 |
Correct |
76 ms |
29568 KB |
Output is correct |
25 |
Correct |
75 ms |
30404 KB |
Output is correct |
26 |
Correct |
72 ms |
29580 KB |
Output is correct |
27 |
Correct |
72 ms |
30144 KB |
Output is correct |
28 |
Correct |
75 ms |
29888 KB |
Output is correct |
29 |
Correct |
72 ms |
29644 KB |
Output is correct |
30 |
Correct |
72 ms |
29584 KB |
Output is correct |
31 |
Correct |
73 ms |
30144 KB |
Output is correct |
32 |
Correct |
72 ms |
29896 KB |
Output is correct |
33 |
Correct |
76 ms |
30604 KB |
Output is correct |
34 |
Correct |
75 ms |
30660 KB |
Output is correct |
35 |
Correct |
74 ms |
29892 KB |
Output is correct |
36 |
Correct |
73 ms |
29580 KB |
Output is correct |
37 |
Correct |
72 ms |
30152 KB |
Output is correct |
38 |
Correct |
79 ms |
30660 KB |
Output is correct |
39 |
Correct |
76 ms |
29584 KB |
Output is correct |
40 |
Correct |
75 ms |
30148 KB |
Output is correct |
41 |
Correct |
72 ms |
29636 KB |
Output is correct |
42 |
Correct |
74 ms |
29564 KB |
Output is correct |
43 |
Correct |
79 ms |
29632 KB |
Output is correct |
44 |
Correct |
86 ms |
29560 KB |
Output is correct |
45 |
Correct |
89 ms |
29564 KB |
Output is correct |
46 |
Correct |
75 ms |
29644 KB |
Output is correct |
47 |
Correct |
74 ms |
29632 KB |
Output is correct |
48 |
Correct |
78 ms |
29636 KB |
Output is correct |
49 |
Correct |
74 ms |
30148 KB |
Output is correct |
50 |
Correct |
75 ms |
29640 KB |
Output is correct |
51 |
Correct |
76 ms |
30144 KB |
Output is correct |
52 |
Correct |
75 ms |
30148 KB |
Output is correct |
53 |
Correct |
75 ms |
30152 KB |
Output is correct |
54 |
Correct |
76 ms |
30404 KB |
Output is correct |
55 |
Correct |
76 ms |
29576 KB |
Output is correct |
56 |
Correct |
79 ms |
30048 KB |
Output is correct |
57 |
Correct |
81 ms |
29568 KB |
Output is correct |
58 |
Correct |
75 ms |
29816 KB |
Output is correct |
59 |
Correct |
75 ms |
29636 KB |
Output is correct |
60 |
Correct |
77 ms |
29632 KB |
Output is correct |
61 |
Correct |
76 ms |
29632 KB |
Output is correct |
62 |
Correct |
75 ms |
30088 KB |
Output is correct |
63 |
Correct |
74 ms |
30400 KB |
Output is correct |
64 |
Correct |
80 ms |
30148 KB |
Output is correct |
65 |
Correct |
77 ms |
29576 KB |
Output is correct |
66 |
Correct |
77 ms |
30412 KB |
Output is correct |
67 |
Correct |
77 ms |
29636 KB |
Output is correct |
68 |
Correct |
76 ms |
29636 KB |
Output is correct |
69 |
Correct |
77 ms |
29576 KB |
Output is correct |
70 |
Correct |
75 ms |
29572 KB |
Output is correct |
71 |
Correct |
78 ms |
30364 KB |
Output is correct |
72 |
Correct |
76 ms |
29636 KB |
Output is correct |
73 |
Correct |
77 ms |
29576 KB |
Output is correct |
74 |
Correct |
76 ms |
29636 KB |
Output is correct |
75 |
Correct |
79 ms |
29624 KB |
Output is correct |
76 |
Correct |
76 ms |
29636 KB |
Output is correct |
77 |
Correct |
76 ms |
29848 KB |
Output is correct |
78 |
Correct |
78 ms |
29632 KB |
Output is correct |
79 |
Correct |
77 ms |
29576 KB |
Output is correct |
80 |
Correct |
78 ms |
30656 KB |
Output is correct |
81 |
Correct |
75 ms |
29632 KB |
Output is correct |
82 |
Correct |
77 ms |
29648 KB |
Output is correct |
83 |
Correct |
77 ms |
29896 KB |
Output is correct |
84 |
Correct |
75 ms |
29632 KB |
Output is correct |