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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD = 998244353;
int char_to_int(char c){
if('a' <= c && c <= 'z'){
return c - 'a';
}
else if('A' <= c && c <= 'Z'){
return c - 'A' + 'z' - 'a' + 1;
}
else{
return c - '0' + 'Z' - 'A' + 'z' - 'a' + 2;
}
}
int n;
string s;
vector<string> stuff[15];
int solve(vector<string> &stuff){
sort(stuff.begin(),stuff.end());
stuff.resize(unique(stuff.begin(),stuff.end()) - stuff.begin());
vector<vector<vector<int>>> cnt(62,vector<vector<int>>(62,vector<int>(62,0)));
vector<vector<int>> words(62,vector<int>(62,0));
for(auto it:stuff){
words[char_to_int(it[0])][char_to_int(it.back())]++;
}
for(int a = 0;a < 62;a++){
for(int b = 0;b < 62;b++){
for(int c = 0;c < 62;c++){
for(int d = 0;d < 62;d++){
cnt[a][b][c] = (cnt[a][b][c] + 1LL * words[a][d] * words[b][d] * words[c][d]) % MOD;
}
}
}
}
int ans = 0;
for(int a = 0;a < 62;a++){
for(int b = 0;b < 62;b++){
for(int c = 0;c < 62;c++){
for(int d = 0;d < 62;d++){
ans = (ans + 1LL * (1LL * cnt[a][b][c] * cnt[a][b][d] % MOD) * (1LL * cnt[a][c][d] * cnt[b][c][d] % MOD)) % MOD;
}
}
}
}
return ans;
}
int main(){
cin >> n;
for(int i = 1;i <= n;i++){
cin >> s;
stuff[s.size()].push_back(s);
reverse(s.begin(),s.end());
stuff[s.size()].push_back(s);
}
int ans = 0;
for(int i = 3;i <= 10;i++){
ans += solve(stuff[i]);
if(ans >= MOD){
ans -= MOD;
}
}
cout << ans;
return 0;
}
# | 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... |