이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define int long long
map<char, int> mp;
int c[11][62][62][62];
int aa[11][63][63];
const int mod = 998244353;
int mul(int x, int y){
if((x*y)>mod) return x*y%mod;
return x*y;
}
void sum(int &a){
if(a>=mod) a-=mod;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int cnt=0;
for(int i='a'; i<='z'; i++) mp[i]=cnt++;
for(int i='A'; i<='Z'; i++) mp[i]=cnt++;
for(int i='0'; i<='9'; i++) mp[i]=cnt++;
int n; cin>>n;
vector<string> s(n), x;
for(auto &i: s){
cin >> i;
string x = i;
reverse(x.begin(), x.end());
if(x<i) i=x;
}
sort(s.begin(), s.end());
for(int i=0; i<n; i++){
if(i==0||s[i]!=s[i-1]) x.push_back(s[i]);
}
s=x;
n = s.size();
for(int i=0; i<n; i++){
string x=s[i];
reverse(x.begin(), x.end());
if(x==s[i]) aa[x.size()][mp[x[0]]][mp[x.back()]]++;
else aa[x.size()][mp[x[0]]][mp[x.back()]]++, aa[x.size()][mp[x.back()]][mp[x[0]]]++;
}
for(int i=3; i<=10; i++){
for(int j=0; j<62; j++){
for(int a=0; a<62; a++){
for(int b=a; b<62; b++){
for(int cc=b; cc<62; cc++){
c[i][a][b][cc] += mul(aa[i][j][a], mul(aa[i][j][b], aa[i][j][cc]));
sum(c[i][a][b][cc]);
}
}
}
}
}
int ans=0;
for(int i=3; i<=10; i++){
for(int a=0; a<62; a++){
for(int b=a; b<62; b++){
for(int cc=b; cc<62; cc++){
for(int d=cc; d<62; d++){
int val = 0;
if(d==a) val = 1;
else if(d==b) val=4;
else if(cc==a) val= 4;
else if(b==a && d==cc) val=6;
else if(d==cc || b==a) val=12;
else if(cc==b) val = 12;
else val=24;
ans += mul(val, mul(mul(c[i][a][b][cc], c[i][a][b][d]), mul(c[i][b][cc][d], c[i][a][cc][d])));
sum(ans);
}
}
}
}
}
cout<<ans;
}
# | 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... |