#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod = 998244353, abc = 56;
//const int mod = 998244353, abc = 26;
void upd(int &a, const int &b) { a = (a + b) % mod; }
int mul(const int &a, const int &b) { return (a * 1ll * b) % (ll)mod; }
int conv(char c)
{
if ('a' <= c && c <= 'z') return c - 'a';
if ('A' <= c && c <= 'Z') return 16 + c - 'A';
//if ('0' <= c && c <= '9') return 26 + 26 + c - '0';
}
int cnt[abc][abc][abc], e[abc][abc], ans = 0;
void solve(const set<string> &v)
{
memset(cnt, 0, sizeof(cnt)), memset(e, 0, sizeof(e));
for (const string &i : v) e[conv(i[0])][conv(i.back())]++;
for (int c1 = 0; c1 < abc; c1++) for (int c2 = 0; c2 < abc; c2++) for (int c3 = 0; c3 < abc; c3++)
for (int ja = 0; ja < abc; ja++)
upd(cnt[c1][c2][c3], mul(mul(e[ja][c1], e[ja][c2]), e[ja][c3]));
for (int c1 = 0; c1 < abc; c1++) for (int c2 = 0; c2 < abc; c2++)
for (int c3 = 0; c3 < abc; c3++) for (int c4 = 0; c4 < abc; c4++)
upd(ans, mul(mul(cnt[c1][c2][c3], cnt[c2][c3][c4]), mul(cnt[c3][c4][c1], cnt[c4][c1][c2])));
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<set<string> > v(11);
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
v[s.size()].insert(s);
reverse(s.begin(), s.end());
v[s.size()].insert(s);
}
for (int i = 3; i <= 10; i++) if (v[i].size()) solve(v[i]);
cout << ans << "\n";
return 0;
}
Compilation message
cubeword.cpp: In function 'int conv(char)':
cubeword.cpp:14:1: warning: control reaches end of non-void function [-Wreturn-type]
14 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1173 ms |
16324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1173 ms |
16324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1173 ms |
16324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1173 ms |
16324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |