QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401622 | #944. Cubeword | nhuang685# | 0 | 0ms | 0kb | C++20 | 2.3kb | 2024-04-29 03:00:51 | 2024-04-29 03:00:52 |
answer
#include <bits/stdc++.h>
const int MOD = 998244353;
struct Mint {
int val = 0;
Mint(int v = 0) : val(v) {
if (val <= -MOD || MOD <= val) {
val %= MOD;
}
if (val < 0) {
val += MOD;
}
}
Mint &operator+=(Mint b) {
val += b.val;
if (val >= MOD) {
val -= MOD;
}
return *this;
}
Mint &operator*=(Mint b) {
val = (int)((int64_t)val * b.val % MOD);
return *this;
}
};
Mint operator+(Mint a, Mint b) { return a += b; }
Mint operator*(Mint a, Mint b) { return a *= b; }
const int MX = 16;
const int LEN = 10;
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int n;
std::cin >> n;
std::set<std::string> ss;
std::vector freq(LEN + 1, std::vector(MX, std::vector<int>(MX)));
for (int i = 0; i < n; ++i) {
std::string s;
std::cin >> s;
int len = (int)s.size();
int st = s[0] - 'a', en = s.back() - 'a';
if (!ss.contains(s)) {
freq[len][st][en]++;
}
ss.insert(s);
std::string t = s;
std::reverse(t.begin(), t.end());
if (!ss.contains(t)) {
freq[len][en][st]++;
}
ss.insert(t);
}
Mint ans = 0;
for (int len = 3; len <= 10; ++len) {
std::vector cur(MX,
std::vector(MX, std::vector(MX, std::vector<Mint>(MX))));
std::vector pre = cur;
for (int i = 0; i < MX; ++i) {
for (int j = 0; j < MX; ++j) {
pre[i][j][i][j] = freq[len][i][j];
}
}
for (int i = 0; i < 4; ++i) {
for (int a = 0; a < MX; ++a) {
for (int b = 0; b < MX; ++b) {
for (int c = 0; c < MX; ++c) {
for (int d = 0; d < MX; ++d) {
for (int e = 0; e < MX; ++e) {
for (int f = 0; f < MX; ++f) {
cur[a][b][c][d] +=
freq[len][e][c] * freq[len][f][d] * pre[a][b][e][f];
}
}
if (i < 3) {
cur[a][b][c][d] *= freq[len][c][d];
}
}
}
}
}
std::swap(cur, pre);
cur.assign(MX, std::vector(MX, std::vector(MX, std::vector<Mint>(MX))));
}
for (int i = 0; i < MX; ++i) {
for (int j = 0; j < MX; ++j) {
ans += pre[i][j][i][j];
}
}
}
std::cout << ans.val << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
100000 aaa aaaa aaaaa aaaaaacb aaaaabfdab aaaaacaeba aaaaacbec aaaaacc aaaaacdde aaaaad aaaaaef aaaaafe aaaab aaaaba aaaabac aaaabcab aaaabdcab aaaabddec aaaabeabd aaaabeeacc aaaac aaaacaafee aaaacabec aaaacad aaaacb aaaacbcbba aaaacbddbe aaaacc aaaacdda aaaacdf aaaacecdca aaaacfceed aaaacfdef aaaad...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%