#include <bits/stdc++.h>
#define SZ 47
using ll = long long;
ll rel[SZ][SZ];
ll tuplas[SZ][SZ][SZ];
ll MOD = 998244353;
std::map<char,int> mapinha;
int cur=0;
int valor(char ch){
if(mapinha.find(ch)!=mapinha.end())return mapinha[ch];
mapinha[ch]=cur;
++cur;
return mapinha[ch];
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int N;
std::cin>>N;
std::map<std::string,bool> mapa[11];
for(int i=0;i!=N;++i){
std::string s;
std::cin >> s;
mapa[s.size()][s]=1;
std::reverse(s.begin(),s.end());
mapa[s.size()][s]=1;
}
ll ans=0;
for(int j=3;j<=10;++j){
for(auto&x:rel)for(auto&y:x)y=0;
for(auto&x:mapa[j]){
rel[valor(x.first[0])][valor(x.first.back())]++;
}
for(int i=0;i!=SZ;++i){
for(int j=i;j!=SZ;++j){
for(int k=j;k!=SZ;++k){
ll tot=0;
for(int u=0;u!=SZ;++u)tot=(tot+((rel[i][u]*rel[j][u]%MOD)*rel[k][u]))%MOD;
tuplas[i][j][k]=tuplas[i][k][j]=tuplas[j][i][k]=tuplas[j][k][i]=tuplas[k][i][j]=tuplas[k][j][i]=tot;
}
}
}
for(int i=0;i!=SZ;++i){
for(int j=0;j!=SZ;++j){
for(int k=0;k!=SZ;++k){
for(int l=0;l!=SZ;++l){
ans=(ans+((tuplas[i][j][k]*tuplas[i][k][l]%MOD)*tuplas[k][l][j]*tuplas[i][j][l]))%MOD;
}
}
}
}
}
std::cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
508 ms |
15632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
508 ms |
15632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
508 ms |
15632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
508 ms |
15632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |