#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const string ex = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
constexpr int P = 998244353;
using i64 = long long;
constexpr int K = 62;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<vector<string>> s(11);
for (int i = 0; i < n; i++) {
string g;
cin >> g;
string t(g.rbegin(), g.rend());
if (t < g)
g = t;
s[g.size()].push_back(g);
}
auto work = [&](vector<string> &s) {
sort(s.begin(), s.end());
s.erase(unique(s.begin(), s.end()), s.end());
int n = s.size();
int cnt[K][K] {}, cntp[K][K] {};
for (int i = 0; i < n; i++) {
int x = ex.find(s[i][0]);
int y = ex.find(s[i].back());
string t(s[i].rbegin(), s[i].rend());
if (s[i] == t) {
cntp[x][y] += 1;
} else {
cnt[x][y] += 1;
cnt[y][x] += 1;
}
}
i64 dp[K][K][K] {};
for (int a = 0; a < K; a++) {
for (int b = 0; b < K; b++) {
for (int c = 0; c < K; c++) {
for (int x = 0; x < K; x++) {
i64 res = ((a == x) * cntp[a][x]) + cnt[a][x];
res = res * (((b == x) * cntp[b][x]) + cnt[b][x]) % P;
res = res * (((c == x) * cntp[c][x]) + cnt[c][x]) % P;
dp[a][b][c] += res;
if (dp[a][b][c] >= P)
dp[a][b][c] -= P;
}
}
}
}
i64 ans = 0;
for (int a = 0; a < K; a++) {
for (int b = 0; b < K; b++) {
for (int c = 0; c < K; c++) {
for (int d = 0; d < K; d++) {
ans += ((dp[a][b][c] * dp[a][c][d]) % P * (dp[a][b][d] * dp[b][c][d]) % P) % P;
if (ans >= P)
ans -= P;
}
}
}
}
return ans;
};
i64 ans = 0;
for (int k = 3; k <= 10; k++) {
ans += work(s[k]);
if (ans >= P)
ans -= P;
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1175 ms |
5516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1175 ms |
5516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1175 ms |
5516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1175 ms |
5516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |