#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
const int N = 8, A = 32, L = 11, mod = 998244353;
const ll infL = 3e18;
int g[N][3] = {{1, 2, 4},
{0, 3, 5},
{0, 3, 6},
{1, 2, 7},
{0, 5, 6},
{1, 4, 7},
{2, 4, 7},
{3, 5, 6}};
int n;
int cnt[A][A][L], used[N];
int ans = 0, len = 0;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
vector<string> stt;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
string ss = s;
reverse(all(ss));
stt.push_back(ss);
stt.push_back(s);
}
sort(all(stt));
stt.resize(unique(all(stt)) - begin(stt));
for (string s: stt) {
++cnt[islower(s[0]) ? int(s[0] - 'a') : s[0] - 'A' + 16][islower(s.back()) ? int(s.back() - 'a') : s.back() - 'A' + 16][sz(s)];
}
for (len = 1; len < L; ++len) {
memset(used, -1, sizeof(used));
for (int x0 = 0; x0 < A; ++x0) {
used[0] = x0;
for (int x3 = 0; x3 < A; ++x3) {
used[3] = x3;
for (int x5 = 0; x5 < A; ++x5) {
used[5] = x5;
for (int x6 = 0; x6 < A; ++x6) {
used[6] = x6;
int nw = 1;
for (int i = 0; i < N; ++i) {
if (used[i] == -1) {
int sum = 0;
for (int x = 0; x < A; ++x) {
int now = 1;
for (int to : g[i]) {
assert(used[to] != -1);
now = (now * (ll)cnt[x][used[to]][len]) % mod;
}
sum = (sum + now) % mod;
}
nw = (nw * (ll)sum) % mod;
}
}
ans = (ans + nw) % mod;
}
}
}
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1193 ms |
8776 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1193 ms |
8776 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1193 ms |
8776 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1193 ms |
8776 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |