이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define pb push_back
const int N=1e6 + 5 ;
const int inf = 1e18 + 7;
const int mod = 998244353;
int g[11][33][33][33];
int v[11][33][33];
int ans = 0;
int n,m,k;
map<char,int>mps;
vector<int>vs;
int ii(char ch){
return mps[ch];
}
void dfs(int i){
}
int cnt = 0;
void solve(){
cin >> n;
map<string,int>mp;
for(int i = 1;i<=n;i++){
string a;
cin >> a;
if(mp[a] == 0){
v[a.size()][ii(a[0])][ii(a[a.size()-1])] += 1;
}
mp[a] += 1;
reverse(all(a));
if(mp[a] == 0){
v[a.size()][ii(a[0])][ii(a[a.size()-1])] += 1;
}
mp[a] += 1;
}
for(int sz = 3;sz<=10;sz++){
for(int i = 0;i<cnt;i++){
for(int j = 0;j<cnt;j++){
for(int l = 0;l<cnt;l++){
for(int u = 0;u<cnt;u++){
g[sz][j][l][u] += ((v[sz][i][j]*v[sz][i][l]) % mod) * (v[sz][i][u])% mod;
g[sz][j][l][u] %= mod;
}
}
}
}
}
map<int,int>pw;
pw[0] = 1;
pw[1] = 1;
pw[2] = 2;
pw[3] = 6;
pw[4] = 24;
for(int sz = 3;sz<=10;sz++){
for(int i = 0;i<cnt;i++){
for(int j = i;j<cnt;j++){
for(int l = j;l<cnt;l++){
for(int u = l;u<cnt;u++){
int ile=24,c=1;
if(i != j){
ile /= pw[c];
c = 1;
}
else c += 1;
if(l != j){
ile /= pw[c];
c = 1;
}
else c += 1;
if(l != u){
ile /= pw[c];
c = 1;
}
else c += 1;
ile /= pw[c];
ans += (((g[sz][i][j][l] * g[sz][i][j][u])% mod) * g[sz][i][l][u]) % mod * g[sz][j][l][u] % mod;
ans *= ile;
ans %= mod;
}
}
}
}
}
cout << ans << '\n';
}
/*
*/
signed main()
{
for(int i = 0;i<='p'-'a';i+=1){
mps['a'+i] = cnt++;
}
for(int i = 0;i<='p'-'a';i+=1){
mps['A'+i] = cnt++;
}
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin>>tt>>n;
while(tt--)solve();
}
# | 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... |