#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const string ex = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
constexpr int P = 998244353;
using i64 = long long;
// assume -P <= x < 2P
int norm(int x) {
if (x < 0) {
x += P;
}
if (x >= P) {
x -= P;
}
return x;
}
template<class T>
T power(T a, int b) {
T res = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) {
res *= a;
}
}
return res;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
int val() const {
return x;
}
Z operator-() const {
return Z(norm(P - x));
}
Z inv() const {
assert(x != 0);
return power(*this, P - 2);
}
Z &operator*=(const Z &rhs) {
x = i64(x) * rhs.x % P;
return *this;
}
Z &operator+=(const Z &rhs) {
x = norm(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = norm(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) {
return *this *= rhs.inv();
}
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
};
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();
Z 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;
}
}
Z dp[K][K][K] {};
for (int a = 0; a < K; a++) {
for (int b = a; b < K; b++) {
for (int c = b; c < K; c++) {
for (int x = 0; x < K; x++) {
Z res = 1;
res *= ((a == x) * cntp[a][x]) + cnt[a][x];
res *= ((b == x) * cntp[b][x]) + cnt[b][x];
res *= ((c == x) * cntp[c][x]) + cnt[c][x];
dp[a][b][c] += res;
}
dp[b][a][c] = dp[b][c][a] = dp[c][a][b] = dp[c][b][a] = dp[a][b][c];
}
}
}
Z 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] * dp[a][b][d] * dp[b][c][d];
}
}
}
}
return ans;
};
Z ans = 0;
for (int k = 3; k <= 10; k++) {
ans += work(s[k]);
}
cout << ans.val() << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1157 ms |
4572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1157 ms |
4572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1157 ms |
4572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1157 ms |
4572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |