#include<bits/stdc++.h>
using namespace std;
#define int long long
int M = 62;
string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
vector<vector<vector<int>>> cnt (11, vector<vector<int>> (M, vector<int> (M)));
vector<int> f = {0,1,2,6,24};
int cntuni(vector<int> arr){
map<int,int> cnt;
for(auto e : arr) cnt[e]++;
int res = 1;
for(auto p : cnt) res *= f[p.second];
return 24 / res;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
map<char,int> mp;
for(int i = 0; i < M; i++) mp[chars[i]] = i;
int N; cin >> N;
set<string> seen;
for(int i = 0; i < N; i++){
string s; cin >> s;
if(seen.count(s)) continue;
cnt[s.length()][mp[s[0]]][mp[s[s.length() - 1]]]++;
seen.insert(s);
reverse(s.begin(), s.end());
if(seen.count(s)) continue;
cnt[s.length()][mp[s[0]]][mp[s[s.length() - 1]]]++;
seen.insert(s);
}
int MOD = 998244353;
int res = 0;
for(int len = 3; len <= 10; len++){
vector<vector<vector<int>>> dp (M, vector<vector<int>> (M, vector<int> (M)));
for(int i = 0; i < M; i++){
for(int j = i; j < M; j++){
for(int k = j; k < M; k++){
for(int l = 0; l < M; l++){
dp[i][j][k] += (cnt[len][i][l] * cnt[len][j][l] * cnt[len][k][l]) % MOD;
dp[i][j][k] %= MOD;
}
}
}
}
for(int i = 0; i < M; i++){
for(int j = i; j < M; j++){
for(int k = j; k < M; k++){
for(int l = k; l < M; l++){
int a = (dp[i][j][k] * dp[i][j][l] % MOD) * (dp[i][k][l] * dp[j][k][l] % MOD) % MOD;
a *= cntuni({i,j,k,l});
a %= MOD;
res += a;
res %= MOD;
}
}
}
}
}
cout << res << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1192 ms |
18300 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1192 ms |
18300 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1192 ms |
18300 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1192 ms |
18300 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |