This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
vector<vector<vector<vector<int>>>> ans (M, vector<vector<vector<int>>> (M, vector<vector<int>> (M, vector<int> (M, -1))));
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;
if(ans[i][j][k][l] != -1) a*=ans[i][j][k][l];
else a *= (ans[i][j][k][l] = cntuni({i,j,k,l}));
a %= MOD;
res += a;
res %= MOD;
}
}
}
}
}
cout << res << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |