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 ar array
typedef int64_t ll;
#define int ll
const int N = 1e5 + 5;
const int M = 62;
const int mod = 119 << 23 | 1;
int is[M][M], pre[M][M][M], cnt[M][M][M][M];
int bp(int a, int b){
int c=1;
while(b){
if(b&1) c = c * 1ll * a % mod;
a = a * 1ll * a % mod, b >>= 1;
} return c;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
vector<string> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
for(auto& x : a[i]){
if('a' <= x && x <= 'z') x = x - 'a';
else if('A' <= x && x <= 'Z') x = x - 'A' + 26;
else if('0' <= x && x <= '9') x = x - '0' + 52;
}
string b = a[i];
reverse(b.begin(), b.end());
a.push_back(b);
}
int p[4] {};
for(int i=0;i<M;i++){
for(int j=0;j<M;j++){
for(int k=0;k<M;k++){
for(int l=0;l<M;l++){
p[0] = i, p[1] = j, p[2] = k, p[3] = l; // = {i, j, k, l};
sort(p, p + 4);
cnt[p[0]][p[1]][p[2]][p[3]]++;
}
}
}
}
sort(a.begin(), a.end());
vector<string> b;
for(int i=0;i<n*2;i++){
if(!i || a[i] != a[i-1]) b.push_back(a[i]);
}
swap(a, b);
sort(a.begin(), a.end(), [&](string& a, string& b){
return a.size() < b.size();
});
n = a.size();
int l = 0, tot = 0;
for(int s=3;s<=10;s++){
memset(is, 0, sizeof is);
int k = l;
while(l < n && (int)a[l].size() == s){
is[a[l][0]][a[l][s-1]]++;
l++;
}
if(l == k) continue;
memset(pre, 0, sizeof pre);
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++){
pre[i][j][k] = (pre[i][j][k] + is[i][l] * 1ll * is[j][l] % mod * is[k][l]) % 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 res = cnt[i][j][k][l] * 1ll * pre[i][j][k] % mod;
res = res * 1ll * pre[i][j][l] % mod;
res = res * 1ll * pre[i][k][l] % mod;
res = res * 1ll * pre[j][k][l] % mod;
tot += res;
if(tot >= mod) tot -= mod;
}
}
}
}
}
//~ cout<<tot<<"\n";
//~ tot = tot * 1ll * bp(6, mod - 2) % mod;
cout<<tot<<"\n";
}
Compilation message (stderr)
cubeword.cpp: In function 'int main()':
cubeword.cpp:68:14: warning: array subscript has type 'char' [-Wchar-subscripts]
68 | is[a[l][0]][a[l][s-1]]++;
| ^
cubeword.cpp:68:25: warning: array subscript has type 'char' [-Wchar-subscripts]
68 | is[a[l][0]][a[l][s-1]]++;
| ^
# | 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... |