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 ll long long
#define ar array
const int mxN=1e5, K=62, M=998244353;
int n;
string s[mxN];
ll cnt[K][K], dp[K][K][K];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i=0; i<n; ++i)
cin >> s[i];
ll ans=0;
for (int i=3; i<=10; ++i) {
set<string> st;
for (int j=0; j<n; ++j)
if (s[j].size()==i)
for (int rep=0; rep<2; ++rep) {
st.insert(s[j]);
reverse(s[j].begin(), s[j].end());
}
memset(cnt, 0, sizeof(cnt));
for (string x : st) {
int a='a'<=x[0]&&x[0]<='z'?x[0]-'a':'A'<=x[0]&&x[0]<='Z'?26+x[0]-'A':52+x[0]-'0';
int b='a'<=x.back()&&x.back()<='z'?x.back()-'a':'A'<=x.back()&&x.back()<='Z'?26+x.back()-'A':52+x.back()-'0';
++cnt[a][b];
}
memset(dp, 0, sizeof(dp));
for (int a=0; a<K; ++a)
for (int b=a; b<K; ++b)
for (int c=b; c<K; ++c)
for (int d=0; d<K; ++d)
dp[a][b][c]=(dp[a][b][c]+cnt[d][a]*cnt[d][b]*cnt[d][c])%M;
auto Consider=[&](int a, int b, int c, int d, int mul) {
ans=(ans+mul*dp[a][b][c]%M*dp[a][b][d]%M*dp[a][c][d]%M*dp[b][c][d])%M;
};
//cout << dp['r'-'a']['r'-'a']['r'-'a'] << endl;
for (int a=0; a<K; ++a) {
Consider(a, a, a, a, 1);
for (int b=a+1; b<K; ++b) {
Consider(a, a, a, b, 4);
Consider(a, a, b, b, 6);
Consider(a, b, b, b, 4);
for (int c=b+1; c<K; ++c) {
Consider(a, b, c, c, 12);
Consider(a, b, b, c, 12);
Consider(a, a, b, c, 12);
for (int d=c+1; d<K; ++d)
Consider(a, b, c, d, 24);
}
}
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
cubeword.cpp: In function 'int main()':
cubeword.cpp:22:19: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
22 | if (s[j].size()==i)
| ~~~~~~~~~~~^~~
# | 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... |