이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 62, L = 8, 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[L][A][A], dp2[A][A][A], dp7[A][A][A], dp1[A][A][A], dp4[A][A][A];
int ans = 0;
int len = 0;
int get(char c) {
if ('a' <= c && c <= 'z') {
return c - 'a';
}
if ('A' <= c && c <= 'Z') {
return (c - 'A') + 26;
}
return (c - '0') + 52;
}
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));
if (ss != s)
stt.push_back(ss);
stt.push_back(s);
}
sort(all(stt));
stt.resize(unique(all(stt)) - begin(stt));
for (string s: stt) {
++cnt[sz(s) - 3][get(s[0])][get(s.back())];
}
for (len = 0; len < L; ++len) {
for (int x0 = 0; x0 < A; ++x0) {
for (int x3 = 0; x3 < A; ++x3) {
for (int x6 = 0; x6 < A; ++x6) {
ll sum = 0;
for (int x = 0; x < A; ++x) {
sum += cnt[len][x][x0] * cnt[len][x][x3] * cnt[len][x][x6];
}
dp2[x0][x3][x6] = dp7[x0][x3][x6] = dp1[x0][x3][x6] = dp4[x0][x3][x6] = sum % mod;
}
}
}
for (int x0 = 0; x0 < A; ++x0) {
for (int x3 = 0; x3 < A; ++x3) {
for (int x5 = 0; x5 < A; ++x5) {
for (int x6 = 0; x6 < A; ++x6) {
ans = (ans + dp4[x0][x5][x6] * (ll) dp7[x3][x5][x6] % mod * dp1[x0][x3][x5] % mod *
dp2[x0][x3][x6]) % mod;
}
}
}
}
}
cout << ans;
return 0;
}
# | 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... |