#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
namespace
{
const int N = 11, K = 128, MOD = 998244353;
int cnt[N][K][K]{}, res[K][K][K]{};
const string charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
inline void addmod(int &x, int y)
{
x += y;
if (x > MOD)
{
x -= MOD;
}
}
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<string> a(n);
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
string ss = s;
reverse(ss.begin(), ss.end());
if (ss < s)
{
swap(s, ss);
}
a[i] = s;
}
sort(a.begin(), a.end());
a.resize(unique(a.begin(), a.end()) - a.begin());
n = a.size();
for (int i = 0; i < n; i++)
{
string s = a[i], ss = s;
reverse(ss.begin(), ss.end());
if (s == ss)
{
cnt[s.size()][s[0]][ss[0]]++;
}
else
{
cnt[s.size()][s[0]][ss[0]]++;
cnt[s.size()][ss[0]][s[0]]++;
}
}
int ans = 0;
for (int t = 3; t < N; t++)
{
for (int i : charset)
{
for (int j : charset)
{
for (int k : charset)
{
res[i][j][k] = 0;
}
}
}
for (int l : charset)
{
for (int i : charset)
{
if (cnt[t][i][l] == 0)
{
continue;
}
for (int j : charset)
{
if (cnt[t][j][l] == 0)
{
continue;
}
for (int k : charset)
{
if (cnt[t][k][l] == 0)
{
continue;
}
// (res[i][j][k] += 1ll * cnt[t][i][l] * cnt[t][j][l] * cnt[t][k][l]) %= MOD;
addmod(res[i][j][k], 1ll * cnt[t][i][l] * cnt[t][j][l] * cnt[t][k][l] % MOD);
}
}
}
}
for (int i : charset)
{
for (int j : charset)
{
for (int k : charset)
{
if (res[i][j][k] == 0)
{
continue;
}
for (int l : charset)
{
// (ans += res[i][j][k] * res[i][j][l] % MOD * res[i][k][l] % MOD * res[j][k][l]) %= MOD;
addmod(ans, 1ll * res[i][j][k] * res[i][j][l] % MOD * res[i][k][l] % MOD * res[j][k][l] % MOD);
}
}
}
}
}
cout << ans << '\n';
return 0;
}
Compilation message
cubeword.cpp: In function 'int main()':
cubeword.cpp:47:31: warning: array subscript has type 'char' [-Wchar-subscripts]
47 | cnt[s.size()][s[0]][ss[0]]++;
| ^
cubeword.cpp:47:38: warning: array subscript has type 'char' [-Wchar-subscripts]
47 | cnt[s.size()][s[0]][ss[0]]++;
| ^
cubeword.cpp:51:31: warning: array subscript has type 'char' [-Wchar-subscripts]
51 | cnt[s.size()][s[0]][ss[0]]++;
| ^
cubeword.cpp:51:38: warning: array subscript has type 'char' [-Wchar-subscripts]
51 | cnt[s.size()][s[0]][ss[0]]++;
| ^
cubeword.cpp:52:32: warning: array subscript has type 'char' [-Wchar-subscripts]
52 | cnt[s.size()][ss[0]][s[0]]++;
| ^
cubeword.cpp:52:38: warning: array subscript has type 'char' [-Wchar-subscripts]
52 | cnt[s.size()][ss[0]][s[0]]++;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
9820 KB |
Output is correct |
2 |
Correct |
38 ms |
9744 KB |
Output is correct |
3 |
Correct |
38 ms |
9556 KB |
Output is correct |
4 |
Correct |
38 ms |
9816 KB |
Output is correct |
5 |
Correct |
38 ms |
9556 KB |
Output is correct |
6 |
Correct |
39 ms |
9744 KB |
Output is correct |
7 |
Correct |
39 ms |
9556 KB |
Output is correct |
8 |
Correct |
39 ms |
9816 KB |
Output is correct |
9 |
Correct |
39 ms |
9556 KB |
Output is correct |
10 |
Correct |
42 ms |
9752 KB |
Output is correct |
11 |
Correct |
40 ms |
9552 KB |
Output is correct |
12 |
Correct |
39 ms |
9556 KB |
Output is correct |
13 |
Correct |
41 ms |
9556 KB |
Output is correct |
14 |
Correct |
39 ms |
9556 KB |
Output is correct |
15 |
Correct |
39 ms |
9552 KB |
Output is correct |
16 |
Correct |
40 ms |
9808 KB |
Output is correct |
17 |
Correct |
39 ms |
9556 KB |
Output is correct |
18 |
Correct |
39 ms |
9556 KB |
Output is correct |
19 |
Correct |
40 ms |
9556 KB |
Output is correct |
20 |
Correct |
42 ms |
9740 KB |
Output is correct |
21 |
Correct |
40 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
9820 KB |
Output is correct |
2 |
Correct |
38 ms |
9744 KB |
Output is correct |
3 |
Correct |
38 ms |
9556 KB |
Output is correct |
4 |
Correct |
38 ms |
9816 KB |
Output is correct |
5 |
Correct |
38 ms |
9556 KB |
Output is correct |
6 |
Correct |
39 ms |
9744 KB |
Output is correct |
7 |
Correct |
39 ms |
9556 KB |
Output is correct |
8 |
Correct |
39 ms |
9816 KB |
Output is correct |
9 |
Correct |
39 ms |
9556 KB |
Output is correct |
10 |
Correct |
42 ms |
9752 KB |
Output is correct |
11 |
Correct |
40 ms |
9552 KB |
Output is correct |
12 |
Correct |
39 ms |
9556 KB |
Output is correct |
13 |
Correct |
41 ms |
9556 KB |
Output is correct |
14 |
Correct |
39 ms |
9556 KB |
Output is correct |
15 |
Correct |
39 ms |
9552 KB |
Output is correct |
16 |
Correct |
40 ms |
9808 KB |
Output is correct |
17 |
Correct |
39 ms |
9556 KB |
Output is correct |
18 |
Correct |
39 ms |
9556 KB |
Output is correct |
19 |
Correct |
40 ms |
9556 KB |
Output is correct |
20 |
Correct |
42 ms |
9740 KB |
Output is correct |
21 |
Correct |
40 ms |
9820 KB |
Output is correct |
22 |
Correct |
52 ms |
10000 KB |
Output is correct |
23 |
Correct |
54 ms |
9752 KB |
Output is correct |
24 |
Correct |
51 ms |
9744 KB |
Output is correct |
25 |
Correct |
52 ms |
9808 KB |
Output is correct |
26 |
Correct |
55 ms |
9820 KB |
Output is correct |
27 |
Correct |
52 ms |
9812 KB |
Output is correct |
28 |
Correct |
55 ms |
9812 KB |
Output is correct |
29 |
Correct |
51 ms |
9812 KB |
Output is correct |
30 |
Correct |
61 ms |
9752 KB |
Output is correct |
31 |
Correct |
54 ms |
9748 KB |
Output is correct |
32 |
Correct |
52 ms |
9820 KB |
Output is correct |
33 |
Correct |
53 ms |
9580 KB |
Output is correct |
34 |
Correct |
54 ms |
9812 KB |
Output is correct |
35 |
Correct |
51 ms |
9808 KB |
Output is correct |
36 |
Correct |
53 ms |
9808 KB |
Output is correct |
37 |
Correct |
63 ms |
9824 KB |
Output is correct |
38 |
Correct |
52 ms |
9808 KB |
Output is correct |
39 |
Correct |
51 ms |
9756 KB |
Output is correct |
40 |
Correct |
52 ms |
9820 KB |
Output is correct |
41 |
Correct |
51 ms |
9812 KB |
Output is correct |
42 |
Correct |
59 ms |
9808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
9820 KB |
Output is correct |
2 |
Correct |
38 ms |
9744 KB |
Output is correct |
3 |
Correct |
38 ms |
9556 KB |
Output is correct |
4 |
Correct |
38 ms |
9816 KB |
Output is correct |
5 |
Correct |
38 ms |
9556 KB |
Output is correct |
6 |
Correct |
39 ms |
9744 KB |
Output is correct |
7 |
Correct |
39 ms |
9556 KB |
Output is correct |
8 |
Correct |
39 ms |
9816 KB |
Output is correct |
9 |
Correct |
39 ms |
9556 KB |
Output is correct |
10 |
Correct |
42 ms |
9752 KB |
Output is correct |
11 |
Correct |
40 ms |
9552 KB |
Output is correct |
12 |
Correct |
39 ms |
9556 KB |
Output is correct |
13 |
Correct |
41 ms |
9556 KB |
Output is correct |
14 |
Correct |
39 ms |
9556 KB |
Output is correct |
15 |
Correct |
39 ms |
9552 KB |
Output is correct |
16 |
Correct |
40 ms |
9808 KB |
Output is correct |
17 |
Correct |
39 ms |
9556 KB |
Output is correct |
18 |
Correct |
39 ms |
9556 KB |
Output is correct |
19 |
Correct |
40 ms |
9556 KB |
Output is correct |
20 |
Correct |
42 ms |
9740 KB |
Output is correct |
21 |
Correct |
40 ms |
9820 KB |
Output is correct |
22 |
Correct |
52 ms |
10000 KB |
Output is correct |
23 |
Correct |
54 ms |
9752 KB |
Output is correct |
24 |
Correct |
51 ms |
9744 KB |
Output is correct |
25 |
Correct |
52 ms |
9808 KB |
Output is correct |
26 |
Correct |
55 ms |
9820 KB |
Output is correct |
27 |
Correct |
52 ms |
9812 KB |
Output is correct |
28 |
Correct |
55 ms |
9812 KB |
Output is correct |
29 |
Correct |
51 ms |
9812 KB |
Output is correct |
30 |
Correct |
61 ms |
9752 KB |
Output is correct |
31 |
Correct |
54 ms |
9748 KB |
Output is correct |
32 |
Correct |
52 ms |
9820 KB |
Output is correct |
33 |
Correct |
53 ms |
9580 KB |
Output is correct |
34 |
Correct |
54 ms |
9812 KB |
Output is correct |
35 |
Correct |
51 ms |
9808 KB |
Output is correct |
36 |
Correct |
53 ms |
9808 KB |
Output is correct |
37 |
Correct |
63 ms |
9824 KB |
Output is correct |
38 |
Correct |
52 ms |
9808 KB |
Output is correct |
39 |
Correct |
51 ms |
9756 KB |
Output is correct |
40 |
Correct |
52 ms |
9820 KB |
Output is correct |
41 |
Correct |
51 ms |
9812 KB |
Output is correct |
42 |
Correct |
59 ms |
9808 KB |
Output is correct |
43 |
Correct |
165 ms |
9808 KB |
Output is correct |
44 |
Correct |
164 ms |
9920 KB |
Output is correct |
45 |
Correct |
175 ms |
9724 KB |
Output is correct |
46 |
Correct |
165 ms |
9808 KB |
Output is correct |
47 |
Correct |
174 ms |
9812 KB |
Output is correct |
48 |
Correct |
166 ms |
9808 KB |
Output is correct |
49 |
Correct |
165 ms |
9808 KB |
Output is correct |
50 |
Correct |
169 ms |
9740 KB |
Output is correct |
51 |
Correct |
167 ms |
9808 KB |
Output is correct |
52 |
Correct |
165 ms |
9680 KB |
Output is correct |
53 |
Correct |
168 ms |
9808 KB |
Output is correct |
54 |
Correct |
167 ms |
9820 KB |
Output is correct |
55 |
Correct |
174 ms |
9808 KB |
Output is correct |
56 |
Correct |
174 ms |
9812 KB |
Output is correct |
57 |
Correct |
166 ms |
9812 KB |
Output is correct |
58 |
Correct |
166 ms |
9748 KB |
Output is correct |
59 |
Correct |
169 ms |
9808 KB |
Output is correct |
60 |
Correct |
167 ms |
9744 KB |
Output is correct |
61 |
Correct |
169 ms |
9740 KB |
Output is correct |
62 |
Correct |
171 ms |
9812 KB |
Output is correct |
63 |
Correct |
166 ms |
9808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
9820 KB |
Output is correct |
2 |
Correct |
38 ms |
9744 KB |
Output is correct |
3 |
Correct |
38 ms |
9556 KB |
Output is correct |
4 |
Correct |
38 ms |
9816 KB |
Output is correct |
5 |
Correct |
38 ms |
9556 KB |
Output is correct |
6 |
Correct |
39 ms |
9744 KB |
Output is correct |
7 |
Correct |
39 ms |
9556 KB |
Output is correct |
8 |
Correct |
39 ms |
9816 KB |
Output is correct |
9 |
Correct |
39 ms |
9556 KB |
Output is correct |
10 |
Correct |
42 ms |
9752 KB |
Output is correct |
11 |
Correct |
40 ms |
9552 KB |
Output is correct |
12 |
Correct |
39 ms |
9556 KB |
Output is correct |
13 |
Correct |
41 ms |
9556 KB |
Output is correct |
14 |
Correct |
39 ms |
9556 KB |
Output is correct |
15 |
Correct |
39 ms |
9552 KB |
Output is correct |
16 |
Correct |
40 ms |
9808 KB |
Output is correct |
17 |
Correct |
39 ms |
9556 KB |
Output is correct |
18 |
Correct |
39 ms |
9556 KB |
Output is correct |
19 |
Correct |
40 ms |
9556 KB |
Output is correct |
20 |
Correct |
42 ms |
9740 KB |
Output is correct |
21 |
Correct |
40 ms |
9820 KB |
Output is correct |
22 |
Correct |
52 ms |
10000 KB |
Output is correct |
23 |
Correct |
54 ms |
9752 KB |
Output is correct |
24 |
Correct |
51 ms |
9744 KB |
Output is correct |
25 |
Correct |
52 ms |
9808 KB |
Output is correct |
26 |
Correct |
55 ms |
9820 KB |
Output is correct |
27 |
Correct |
52 ms |
9812 KB |
Output is correct |
28 |
Correct |
55 ms |
9812 KB |
Output is correct |
29 |
Correct |
51 ms |
9812 KB |
Output is correct |
30 |
Correct |
61 ms |
9752 KB |
Output is correct |
31 |
Correct |
54 ms |
9748 KB |
Output is correct |
32 |
Correct |
52 ms |
9820 KB |
Output is correct |
33 |
Correct |
53 ms |
9580 KB |
Output is correct |
34 |
Correct |
54 ms |
9812 KB |
Output is correct |
35 |
Correct |
51 ms |
9808 KB |
Output is correct |
36 |
Correct |
53 ms |
9808 KB |
Output is correct |
37 |
Correct |
63 ms |
9824 KB |
Output is correct |
38 |
Correct |
52 ms |
9808 KB |
Output is correct |
39 |
Correct |
51 ms |
9756 KB |
Output is correct |
40 |
Correct |
52 ms |
9820 KB |
Output is correct |
41 |
Correct |
51 ms |
9812 KB |
Output is correct |
42 |
Correct |
59 ms |
9808 KB |
Output is correct |
43 |
Correct |
165 ms |
9808 KB |
Output is correct |
44 |
Correct |
164 ms |
9920 KB |
Output is correct |
45 |
Correct |
175 ms |
9724 KB |
Output is correct |
46 |
Correct |
165 ms |
9808 KB |
Output is correct |
47 |
Correct |
174 ms |
9812 KB |
Output is correct |
48 |
Correct |
166 ms |
9808 KB |
Output is correct |
49 |
Correct |
165 ms |
9808 KB |
Output is correct |
50 |
Correct |
169 ms |
9740 KB |
Output is correct |
51 |
Correct |
167 ms |
9808 KB |
Output is correct |
52 |
Correct |
165 ms |
9680 KB |
Output is correct |
53 |
Correct |
168 ms |
9808 KB |
Output is correct |
54 |
Correct |
167 ms |
9820 KB |
Output is correct |
55 |
Correct |
174 ms |
9808 KB |
Output is correct |
56 |
Correct |
174 ms |
9812 KB |
Output is correct |
57 |
Correct |
166 ms |
9812 KB |
Output is correct |
58 |
Correct |
166 ms |
9748 KB |
Output is correct |
59 |
Correct |
169 ms |
9808 KB |
Output is correct |
60 |
Correct |
167 ms |
9744 KB |
Output is correct |
61 |
Correct |
169 ms |
9740 KB |
Output is correct |
62 |
Correct |
171 ms |
9812 KB |
Output is correct |
63 |
Correct |
166 ms |
9808 KB |
Output is correct |
64 |
Execution timed out |
1112 ms |
10068 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |