#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define MX 62
typedef long long ll;
using namespace std;
const int MOD = 998244353;
int cnt[101][101][101];
int a[8], b[12] = {0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7}, c[12] = {1, 2, 3, 0, 4, 5, 6, 7, 5, 6, 7, 4};
int mp[505], val[11][101][101][101];
bool chk(string &s){
int n = s.size();
for (int i=0;i<n;i++){
int j = n-1-i;
if (i>j) break;
if (s[i]!=s[j]) return 0;
}
return 1;
}
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
unordered_set<string> st[11];
for (int i='a';i<='z';i++){
mp[i] = i-'a';
}
for (int i='A';i<='Z';i++){
mp[i] = i-'A'+26;
}
for (int i='0';i<='9';i++){
mp[i] = i-'0'+52;
}
for (int i=0;i<n;i++){
string s;
cin >> s;
int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
cnt[len][idx1][idx2]++;
cnt[len][idx2][idx1]++;
if (st[len].find(s)!=st[len].end()){
cnt[len][idx1][idx2]--;
cnt[len][idx2][idx1]--;
continue;
}
reverse(s.begin(), s.end());
if (st[len].find(s)!=st[len].end()){
cnt[len][idx1][idx2]--;
cnt[len][idx2][idx1]--;
continue;
}
if (chk(s)) cnt[(int)s.size()][idx2][idx1]--;
st[len].insert(s);
}
for (int len=3;len<=10;len++){
for (int i=0;i<MX;i++){
for (int j=0;j<MX;j++){
for (int k=0;k<MX;k++){
for (int l=0;l<MX;l++){
ll tmp = (ll)cnt[len][i][l] * cnt[len][j][l] %MOD;
tmp = (tmp*cnt[len][k][l])%MOD;
val[len][i][j][k] += tmp;
if (val[len][i][j][k]>=MOD) val[len][i][j][k] -= MOD;
}
}
}
}
}
int ans = 0;
for (int len=3;len<=10;len++){
for (int i=0;i<MX;i++){
for (int j=0;j<MX;j++){
for (int k=0;k<MX;k++){
for (int l=0;l<MX;l++){
ll tmp = val[len][i][j][k];
tmp = (tmp*val[len][i][j][l])%MOD;
tmp = (tmp*val[len][i][k][l])%MOD;
tmp = (tmp*val[len][j][k][l])%MOD;
ans += tmp;
if (ans>=MOD) ans -= MOD;
}
}
}
}
}
printf("%d\n", ans);
return 0;
}
Compilation message
cubeword.cpp: In function 'int main()':
cubeword.cpp:41:27: warning: array subscript has type 'char' [-Wchar-subscripts]
41 | int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
| ^
cubeword.cpp:41:46: warning: array subscript has type 'char' [-Wchar-subscripts]
41 | int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
| ~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1173 ms |
21116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1173 ms |
21116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1173 ms |
21116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1173 ms |
21116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |