#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define pb push_back
const int N=1e6 + 5 ;
const int inf = 1e18 + 7;
const int mod = 998244353;
int g[11][33][33][33];
int v[11][33][33];
int ans = 0;
int n,m,k;
map<char,int>mps;
vector<int>vs;
int ii(char ch){
return mps[ch];
}
void dfs(int i){
}
int cnt = 0;
void solve(){
cin >> n;
map<string,int>mp;
for(int i = 1;i<=n;i++){
string a;
cin >> a;
if(mp[a] == 0){
v[a.size()][ii(a[0])][ii(a[a.size()-1])] += 1;
}
mp[a] += 1;
reverse(all(a));
if(mp[a] == 0){
v[a.size()][ii(a[0])][ii(a[a.size()-1])] += 1;
}
mp[a] += 1;
}
for(int sz = 3;sz<=10;sz++){
for(int i = 0;i<cnt;i++){
for(int j = 0;j<cnt;j++){
for(int l = 0;l<cnt;l++){
for(int u = 0;u<cnt;u++){
g[sz][j][l][u] += (v[sz][i][j]*v[sz][i][l]*v[sz][i][u]);
g[sz][j][l][u] %= mod;
}
}
}
}
}
for(int sz = 3;sz<=10;sz++){
for(int i = 0;i<cnt;i++){
for(int j = 0;j<cnt;j++){
for(int l = 0;l<cnt;l++){
for(int u = 0;u<cnt;u++){
ans += g[sz][i][j][l] * g[sz][i][j][u] * g[sz][i][l][u] * g[sz][j][l][u];
ans %= mod;
}
}
}
}
}
cout << ans << '\n';
}
/*
*/
signed main()
{
for(int i = 0;i<='p'-'a';i+=1){
mps['a'+i] = cnt++;
}
for(int i = 0;i<='p'-'a';i+=1){
mps['A'+i] = cnt++;
}
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin>>tt>>n;
while(tt--)solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
178 ms |
17940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
178 ms |
17940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
178 ms |
17940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
178 ms |
17940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |